[yt-svn] commit/yt: ngoldbaum: Merged in john_regan/yt-phase-dev (pull request #980)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Jul 18 09:38:28 PDT 2014
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/ad16dc5a05fd/
Changeset: ad16dc5a05fd
Branch: yt
User: ngoldbaum
Date: 2014-07-18 18:38:20
Summary: Merged in john_regan/yt-phase-dev (pull request #980)
Added a number of helper routines to PhasePlot
Affected #: 3 files
diff -r e89295c7393d410f8d3f1f2868d1fbad428cd654 -r ad16dc5a05fdaf6cd84949869b4d847791b4cddc yt/visualization/plot_container.py
--- a/yt/visualization/plot_container.py
+++ b/yt/visualization/plot_container.py
@@ -109,6 +109,9 @@
font_path = matplotlib.get_data_path() + '/fonts/ttf/STIXGeneral.ttf'
self._font_properties = FontProperties(size=fontsize, fname=font_path)
self._font_color = None
+ self._xlabel = None
+ self._ylabel = None
+ self._colorbarlabel = None
@invalidate_plot
def set_log(self, field, log):
@@ -475,3 +478,67 @@
img = base64.b64encode(self.plots[field]._repr_png_())
ret += '<img src="data:image/png;base64,%s"><br>' % img
return ret
+
+ def set_xlabel(self, x_title, fontsize=18):
+ r"""
+ Allow the user to modify the X-axis title
+ Defaults to the global value. Fontsize defaults
+ to 18.
+
+ Parameters
+ ----------
+ x_title: str
+ The new string for the x-axis. This is a required argument.
+
+ fontsize: float
+ Fontsize for the x-axis title
+
+ >>> plot.set_xtitle("H2I Number Density (cm$^{-3}$)")
+
+ """
+ for f in self.plots:
+ self.plots[f].axes.xaxis.set_label_text(x_title, fontsize=fontsize)
+ self._xlabel = x_title
+
+ def set_ylabel(self, y_title, fontsize=18):
+ r"""
+ Allow the user to modify the Y-axis title
+ Defaults to the global value. Fontsize defaults
+ to 18.
+
+ Parameters
+ ----------
+ y_title: str
+ The new string for the y-axis. This is a required argument.
+ fontsize: float
+ Fontsize for the y-axis title
+
+ >>> plot.set_ytitle("Temperature (K)")
+
+ """
+ for f in self.plots:
+ self.plots[f].axes.yaxis.set_label_text(y_title, fontsize=fontsize)
+ self._ylabel = y_title
+
+ def set_colorbar_label(self, z_title, fontsize=18):
+ r"""
+ Allow the user to modify the Z-axis title
+ Defaults to the global value. Fontsize defaults
+ to 18.
+
+ Parameters
+ ----------
+ z_title: str
+ The new string for the colorbar. This is a required argument.
+ fontsize: float
+ Fontsize for the z-axis title
+
+ >>> plot.set_ztitle("Enclosed Gas Mass ($M_{\odot}$)")
+
+ """
+ for f in self.plots:
+ self.plots[f].cax.yaxis.set_label_text(z_title, fontsize=fontsize)
+ self._colorbarlabel = z_title
+
+ def _get_axes_labels(self):
+ return(self._xlabel, self._ylabel, self._colorbarlabel)
diff -r e89295c7393d410f8d3f1f2868d1fbad428cd654 -r ad16dc5a05fdaf6cd84949869b4d847791b4cddc yt/visualization/profile_plotter.py
--- a/yt/visualization/profile_plotter.py
+++ b/yt/visualization/profile_plotter.py
@@ -517,11 +517,10 @@
weight_field=None)
>>> plot.save()
- >>> # Change plot properties.
+ >>> # Change plot properties.
>>> plot.set_cmap("CellMassMsun", "jet")
>>> plot.set_zlim("CellMassMsun", 1e8, 1e13)
>>> plot.set_title("CellMassMsun", "This is a phase plot")
-
"""
x_log = None
y_log = None
@@ -532,6 +531,7 @@
_plot_valid = False
_plot_type = 'Phase'
+
def __init__(self, data_source, x_field, y_field, z_fields,
weight_field="CellMassMsun", x_bins=128, y_bins=128,
accumulation=False, fractional=False,
@@ -540,6 +540,14 @@
self.z_log = {}
self.z_title = {}
self._initfinished = False
+ self._xlimits = [0,0]
+ self._ylimits = [0,0]
+ self._setxlims = False
+ self._setylims = False
+ self._plottext = ""
+ self._textxpos = 0.0
+ self._textypos = 0.0
+
if profile is None:
profile = create_profile(data_source,
@@ -562,10 +570,11 @@
xfi = pf.field_info[field_x]
yfi = pf.field_info[field_y]
zfi = pf.field_info[field_z]
+
x_title = self.x_title or self._get_field_label(field_x, xfi)
y_title = self.y_title or self._get_field_label(field_y, yfi)
z_title = self.z_title.get(field_z, None) or \
- self._get_field_label(field_z, zfi)
+ self._get_field_label(field_z, zfi)
return (x_title, y_title, z_title)
def _get_field_label(self, field, field_info):
@@ -612,7 +621,16 @@
size = (self.figure_size, self.figure_size)
x_scale, y_scale, z_scale = self._get_field_log(f, self.profile)
+ x_label, y_label, z_label = self._get_axes_labels()
x_title, y_title, z_title = self._get_field_title(f, self.profile)
+ #If the labels are set they take precedence
+ if x_label is not None:
+ x_title = x_label
+ if y_label is not None:
+ y_title = y_label
+ if z_label is not None:
+ z_title = z_label
+
if f in self.plots:
zlim = [self.plots[f].zmin, self.plots[f].zmax]
else:
@@ -627,16 +645,24 @@
x_scale, y_scale, z_scale,
self._colormaps[f], zlim, size, fp.get_size(),
fig, axes, cax)
+
self.plots[f].axes.xaxis.set_label_text(x_title)
self.plots[f].axes.yaxis.set_label_text(y_title)
self.plots[f].cax.yaxis.set_label_text(z_title)
+ if(self._setxlims == True):
+ self.plots[f].axes.set_xlim(self._xlimits[0], self._xlimits[1])
+ if(self._setylims == True):
+ self.plots[f].axes.set_ylim(self._ylimits[0], self._ylimits[1])
+
+ self.plots[f].axes.text(self._textxpos, self._textypos, self._plottext,
+ fontproperties=self._font_properties)
if z_scale == "log":
self._field_transform[f] = log_transform
else:
self._field_transform[f] = linear_transform
if f in self.plot_title:
self.plots[f].axes.set_title(self.plot_title[f])
-
+
if self._font_color is not None:
ax = self.plots[f].axes
cbax = self.plots[f].cb.ax
@@ -648,6 +674,90 @@
label.set_color(self._font_color)
self._plot_valid = True
+
+ def set_xlim(self, xmin=None, xmax=None):
+ r"""
+ Sets the x-axis limits on the Phase plot.
+ Defaults to None leaving the axis unchanged
+ Parameters
+ ----------
+ xmin: float
+ The minimum value on the x-axis
+ xmax: float
+ The maximum value on the x-axis
+
+ >>> plot.set_xlim(5e-21, 1e5)
+ """
+
+ for f, data in self.profile.field_data.items():
+ axes = None
+ if f in self.plots:
+ if self.plots[f].figure is not None:
+ axes = self.plots[f].axes
+
+ self.plots[f].axes.set_xlim(xmin, xmax)
+ self._setxlims = True
+ self._xlimits[0] = xmin
+ self._xlimits[1] = xmax
+
+ def set_ylim(self, ymin=None, ymax=None):
+ r"""
+ Sets the y-axis limits on the Phase plot.
+ Defaults to None leaving the axis unchanged
+ Parameters
+ ----------
+ ymin: float
+ The minimum value on the y-axis
+ ymax: float
+ The maximum value on the y-axis
+
+ >>> plot.set_ylim(1e1, 1e5)
+
+ """
+
+ for f, data in self.profile.field_data.items():
+ axes = None
+ if f in self.plots:
+ if self.plots[f].figure is not None:
+ axes = self.plots[f].axes
+
+ self.plots[f].axes.set_ylim(ymin, ymax)
+ self._setylims = True
+ self._ylimits[0] = ymin
+ self._ylimits[1] = ymax
+
+ def add_text(self, text_str, xpos, ypos, fontsize=18, **kwargs):
+ r"""
+ Allow the user to insert text onto the plot
+ The x-position and y-position must be given as well as the text string.
+ Add text_str plot at location x, y, data coordinates (see example below).
+ Fontsize defaults to 18.
+
+ Parameters
+ ----------
+ text_str: str
+ The text to insert onto the plot. Required argument.
+ xpos: float
+ Position on plot in x-coordinates. Required argument.
+ ypos: float
+ Position on plot in y-coordinates. Required argument.
+ fontsize: float
+ Fontsize for the text (defaults to 18)
+
+ >>> plot.text(1e-15, 5e4, "Hello YT")
+
+ """
+ for f, data in self.profile.field_data.items():
+ axes = None
+ if f in self.plots:
+ if self.plots[f].figure is not None:
+ axes = self.plots[f].axes
+ self.plots[f].axes.text(xpos, ypos, text_str,
+ fontproperties=self._font_properties)
+ self._plottext = text_str
+ self._textxpos = xpos
+ self._textypos = ypos
+
def save(self, name=None, mpl_kwargs=None):
r"""
Saves a 2d profile plot.
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list