[yt-svn] commit/yt: 7 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Dec 4 12:54:40 PST 2013
7 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/6c19af205bde/
Changeset: 6c19af205bde
Branch: yt
User: jwise77
Date: 2013-12-02 22:50:00
Summary: Adding support for PlotWindows in the multiplot eps_writer routine.
Also, adding support for the user to specify the location of the
colorbar if the routine's default placement is not optimal.
Affected #: 1 file
diff -r d2614f8a1367a0c184e52f6e7632a83741f07702 -r 6c19af205bde79dfc26fec7ada8c5f25a98c5200 yt/visualization/eps_writer.py
--- a/yt/visualization/eps_writer.py
+++ b/yt/visualization/eps_writer.py
@@ -26,6 +26,7 @@
from .plot_types import \
VMPlot, \
ProfilePlot
+from .plot_collection import PlotCollection
from .plot_window import PlotWindow
from .plot_modifications import get_smallest_appropriate_unit
@@ -567,7 +568,7 @@
#=============================================================================
- def colorbar_yt(self, plot, **kwargs):
+ def colorbar_yt(self, plot, field=None, **kwargs):
r"""Wrapper around DualEPS.colorbar to take information from a yt plot.
Accepts all parameters that DualEPS.colorbar takes.
@@ -587,6 +588,8 @@
>>> d.save_fig()
"""
_cmap = None
+ if field != None:
+ self.field = field
if isinstance(plot, PlotWindow):
_cmap = plot._colormaps[self.field]
else:
@@ -783,13 +786,13 @@
#=============================================================================
#=============================================================================
-def multiplot(ncol, nrow, yt_plots=None, images=None, xranges=None,
- yranges=None, xlabels=None, ylabels=None,
+def multiplot(ncol, nrow, yt_plots=None, fields=None, images=None,
+ xranges=None, yranges=None, xlabels=None, ylabels=None,
xdata=None, ydata=None, colorbars=None,
shrink_cb=0.95, figsize=(8,8), margins=(0,0), titles=None,
savefig=None, format="eps", yt_nocbar=False, bare_axes=False,
xaxis_flags=None, yaxis_flags=None,
- cb_flags=None):
+ cb_flags=None, cb_location=None, plot_collection=False):
r"""Convenience routine to create a multi-panel figure from yt plots or
JPEGs. The images are first placed from the origin, and then
bottom-to-top and left-to-right.
@@ -834,6 +837,11 @@
axes.
cb_flags : list of booleans
Flags for each plot to have a colorbar or not.
+ cb_location : list of strings
+ Strings to control the location of the colorbar (left, right,
+ top, bottom)
+ plot_collection : boolean
+ Set to true to yt_plots is a PlotCollection
Examples
--------
@@ -858,8 +866,9 @@
yt plots.
"""
# Error check
+ npanels = ncol*nrow
if images != None:
- if len(images) != ncol*nrow:
+ if len(images) != npanels:
raise RuntimeError("Number of images (%d) doesn't match nrow(%d)"\
" x ncol(%d)." % (len(images), nrow, ncol))
return
@@ -877,16 +886,16 @@
if not _yt:
if xranges is None:
xranges = []
- for i in range(nrow*ncol): xranges.append((0,1))
+ for i in range(npanels): xranges.append((0,1))
if yranges is None:
yranges = []
- for i in range(nrow*ncol): yranges.append((0,1))
+ for i in range(npanels): yranges.append((0,1))
if xlabels is None:
xlabels = []
- for i in range(nrow*ncol): xlabels.append("")
+ for i in range(npanels): xlabels.append("")
if ylabels is None:
ylabels = []
- for i in range(nrow*ncol): ylabels.append("")
+ for i in range(npanels): ylabels.append("")
d = DualEPS(figsize=figsize)
count = 0
@@ -930,12 +939,21 @@
ylabel = ylabels[j]
else:
ylabel = None
- d.insert_image_yt(yt_plots[index], pos=(xpos, ypos))
- d.axis_box_yt(yt_plots[index], pos=(xpos, ypos),
- bare_axes=bare_axes, xaxis_side=xaxis,
- yaxis_side=yaxis,
- xlabel=xlabel, ylabel=ylabel,
- xdata=_xdata, ydata=_ydata)
+ if plot_collection:
+ d.insert_image_yt(yt_plots[index], pos=(xpos, ypos))
+ d.axis_box_yt(yt_plots[index], pos=(xpos, ypos),
+ bare_axes=bare_axes, xaxis_side=xaxis,
+ yaxis_side=yaxis,
+ xlabel=xlabel, ylabel=ylabel,
+ xdata=_xdata, ydata=_ydata)
+ else:
+ d.insert_image_yt(yt_plots, pos=(xpos, ypos),
+ field=fields[index])
+ d.axis_box_yt(yt_plots, pos=(xpos, ypos),
+ bare_axes=bare_axes, xaxis_side=xaxis,
+ yaxis_side=yaxis,
+ xlabel=xlabel, ylabel=ylabel,
+ xdata=_xdata, ydata=_ydata)
else:
d.insert_image(images[index], pos=(xpos,ypos))
d.axis_box(pos = (xpos, ypos),
@@ -964,35 +982,54 @@
if cb_flags != None:
if cb_flags[index] == False:
continue
- if ncol == 1:
- orientation = "right"
+ if cb_location == None:
+ if ncol == 1:
+ orientation = "right"
+ elif i == 0:
+ orientation = "left"
+ elif i+1 == ncol:
+ orientation = "right"
+ elif j == 0:
+ orientation = "bottom"
+ elif j+1 == nrow:
+ orientation = "top"
+ else:
+ orientation = None # Marker for interior plot
+ else:
+ if fields[index] not in cb_location.keys():
+ raise RuntimeError("%s not found in cb_location dict" %
+ fields[index])
+ return
+ orientation = cb_location[fields[index]]
+ if orientation == "right":
xpos = bbox[1]
ypos = ypos0
- elif j == 0:
- orientation = "bottom"
+ elif orientation == "left":
+ xpos = bbox[0]
+ ypos = ypos0
+ elif orientation == "bottom":
ypos = bbox[2]
xpos = xpos0
- elif i == 0:
- orientation = "left"
- xpos = bbox[0]
- ypos = ypos0
- elif i+1 == ncol:
- orientation = "right"
- xpos = bbox[1]
- ypos = ypos0
- elif j+1 == nrow:
- orientation = "top"
+ elif orientation == "top":
ypos = bbox[3]
xpos = xpos0
else:
+ mylog.warning("Unknown colorbar location %s. "
+ "No colorbar displayed." % orientation)
orientation = None # Marker for interior plot
if orientation != None:
if _yt:
- d.colorbar_yt(yt_plots[index],
- pos=[xpos,ypos],
- shrink=shrink_cb,
- orientation=orientation)
+ if plot_collection:
+ d.colorbar_yt(yt_plots[index],
+ pos=[xpos,ypos],
+ shrink=shrink_cb,
+ orientation=orientation)
+ else:
+ d.colorbar_yt(yt_plots, field=fields[index],
+ pos=[xpos,ypos],
+ shrink=shrink_cb,
+ orientation=orientation)
else:
d.colorbar(colorbars[index]["cmap"],
zrange=colorbars[index]["range"],
@@ -1009,8 +1046,8 @@
#=============================================================================
-def multiplot_yt(ncol, nrow, plot_col, **kwargs):
- r"""Wrapper for multiplot that takes a yt PlotCollection.
+def multiplot_yt(ncol, nrow, plots, fields=None, **kwargs):
+ r"""Wrapper for multiplot that takes a yt PlotWindow or PlotCollection.
Accepts all parameters used in multiplot.
@@ -1020,8 +1057,8 @@
Number of columns in the figure.
nrow : integer
Number of rows in the figure.
- plot_col : `PlotCollection`
- yt PlotCollection that has the plots to be used.
+ plots : `PlotCollection` or `PlotWindow`
+ yt PlotCollection or PlotWindow that has the plots to be used.
Examples
--------
@@ -1040,18 +1077,29 @@
>>> mp = multiplot_yt(2,2,pc,savefig="yt",shrink_cb=0.9, bare_axes=False,
>>> yt_nocbar=False, margins=(0.5,0.5))
"""
- if len(plot_col.plots) < nrow*ncol:
- raise RuntimeError("Number of plots in PlotCollection is less "\
- "than nrow(%d) x ncol(%d)." % \
- (len(plot_col.plots), nrow, ncol))
- return
- figure = multiplot(ncol, nrow, yt_plots=plot_col.plots, **kwargs)
+ if isinstance(plots, PlotCollection):
+ if len(plots.plots) < nrow*ncol:
+ raise RuntimeError("Number of plots in PlotCollection is less "\
+ "than nrow(%d) x ncol(%d)." % \
+ (len(plots.plots), nrow, ncol))
+ return
+ figure = multiplot(ncol, nrow, yt_plots=plots.plots, **kwargs)
+ elif isinstance(plots, PlotWindow):
+ if fields == None:
+ fields = plots.fields
+ if len(fields) < nrow*ncol:
+ raise RuntimeError("Number of plots is less "\
+ "than nrow(%d) x ncol(%d)." % \
+ (len(fields), nrow, ncol))
+ return
+ figure = multiplot(ncol, nrow, yt_plots=plots, fields=fields, **kwargs)
return figure
#=============================================================================
-def single_plot(plot, figsize=(12,12), cb_orient="right", bare_axes=False,
- savefig=None, colorbar=True, file_format='eps', **kwargs):
+def single_plot(plot, field=None, figsize=(12,12), cb_orient="right",
+ bare_axes=False, savefig=None, colorbar=True,
+ file_format='eps', **kwargs):
r"""Wrapper for DualEPS routines to create a figure directy from a yt
plot. Calls insert_image_yt, axis_box_yt, and colorbar_yt.
@@ -1080,7 +1128,7 @@
>>> single_plot(p, savefig="figure1")
"""
d = DualEPS(figsize=figsize)
- d.insert_image_yt(plot)
+ d.insert_image_yt(plot, field=field)
d.axis_box_yt(plot, bare_axes=bare_axes, **kwargs)
if colorbar:
d.colorbar_yt(plot, orientation=cb_orient)
https://bitbucket.org/yt_analysis/yt/commits/07827b57a7da/
Changeset: 07827b57a7da
Branch: yt
User: jwise77
Date: 2013-12-03 13:10:28
Summary: Making eps_writer compatible with PhasePlot.
Affected #: 2 files
diff -r 6c19af205bde79dfc26fec7ada8c5f25a98c5200 -r 07827b57a7dac1623d7c5a294d8ebb50e420e3c3 yt/visualization/eps_writer.py
--- a/yt/visualization/eps_writer.py
+++ b/yt/visualization/eps_writer.py
@@ -28,6 +28,7 @@
ProfilePlot
from .plot_collection import PlotCollection
from .plot_window import PlotWindow
+from .profile_plotter import PhasePlot
from .plot_modifications import get_smallest_appropriate_unit
class DualEPS(object):
@@ -58,6 +59,14 @@
#=============================================================================
+ def return_field(self, plot):
+ if isinstance(plot, PlotWindow) or isinstance(plot, PhasePlot):
+ return plot.plots.keys()[0]
+ else:
+ return None
+
+#=============================================================================
+
def axis_box(self, xrange=(0,1), yrange=(0,1), xlabel="", ylabel="",
xlog=False, ylog=False, xdata=None, ydata=None,
tickcolor=None, bare_axes=False,
@@ -276,18 +285,17 @@
>>> d.axis_box_yt(p)
>>> d.save_fig()
"""
- if isinstance(plot, PlotWindow):
+ if isinstance(plot, PlotWindow) or isinstance(plot, PhasePlot):
plot.refresh()
- width = plot.width[0]
else:
plot._redraw_image()
- if isinstance(plot, VMPlot):
- width = plot.width
if isinstance(plot, VMPlot) or isinstance(plot, PlotWindow):
if isinstance(plot, PlotWindow):
data = plot._frb
+ width = plot.width[0]
else:
data = plot.data
+ width = plot.width
if units == None:
units = get_smallest_appropriate_unit(width, plot.pf)
_xrange = (0, width * plot.pf[units])
@@ -315,6 +323,26 @@
_ylabel = 'Image y (%s)' % (units)
if tickcolor == None:
_tickcolor = pyx.color.cmyk.white
+ elif isinstance(plot, PhasePlot):
+ k = plot.plots.keys()[0]
+ _xrange = plot[k].axes.get_xlim()
+ _yrange = plot[k].axes.get_ylim()
+ _xlog = plot.profile.x_log
+ _ylog = plot.profile.y_log
+ if bare_axes:
+ _xlabel = ""
+ _ylabel = ""
+ else:
+ if xlabel != None:
+ _xlabel = xlabel
+ else:
+ _xlabel = plot[k].axes.get_xlabel()
+ if ylabel != None:
+ _ylabel = ylabel
+ else:
+ _xlabel = plot[k].axes.get_ylabel()
+ if tickcolor == None:
+ _tickcolor = None
else:
_xrange = plot._axes.get_xlim()
_yrange = plot._axes.get_ylim()
@@ -413,7 +441,7 @@
plot.colorbar = None
plot._redraw_image()
_p1 = plot._figure
- elif isinstance(plot, PlotWindow):
+ elif isinstance(plot, PlotWindow) or isinstance(plot, PhasePlot):
self.field = field
if self.field == None:
self.field = plot.plots.keys()[0]
@@ -431,6 +459,9 @@
# Remove colorbar
_p1 = plot._figure
_p1.delaxes(_p1.axes[1])
+ else:
+ raise RuntimeError("Unknown plot type")
+
_p1.axes[0].set_axis_off() # remove axes
_p1.axes[0].set_position([-shift,0,1,1]) # rescale figure
_p1.set_facecolor('w') # set background color
@@ -590,7 +621,7 @@
_cmap = None
if field != None:
self.field = field
- if isinstance(plot, PlotWindow):
+ if isinstance(plot, PlotWindow) or isinstance(plot, PhasePlot):
_cmap = plot._colormaps[self.field]
else:
if plot.cmap != None:
@@ -604,10 +635,13 @@
_zlabel = _zlabel.replace("_","\;")
_zlog = plot.log_field
_zrange = (plot.norm.vmin, plot.norm.vmax)
- elif isinstance(plot, PlotWindow):
+ elif isinstance(plot, PlotWindow) or isinstance(plot, PhasePlot):
proj = plot._plot_type.endswith("Projection") and \
plot.data_source.weight_field == None
- _zlabel = plot.pf.field_info[self.field].get_label(proj)
+ if isinstance(plot, PlotWindow):
+ _zlabel = plot.pf.field_info[self.field].get_label(proj)
+ else:
+ _zlabel = plot.data_source.pf.field_info[self.field].get_label(proj)
_zlabel = _zlabel.replace("_","\;")
_zlog = plot.get_log(self.field)[self.field]
if plot.plots[self.field].zmin == None:
@@ -881,6 +915,8 @@
_yt = True
else:
_yt = False
+ if fields == None:
+ fields = [None] * npanels
# If no ranges or labels given and given only images, fill them in.
if not _yt:
@@ -939,21 +975,13 @@
ylabel = ylabels[j]
else:
ylabel = None
- if plot_collection:
- d.insert_image_yt(yt_plots[index], pos=(xpos, ypos))
- d.axis_box_yt(yt_plots[index], pos=(xpos, ypos),
- bare_axes=bare_axes, xaxis_side=xaxis,
- yaxis_side=yaxis,
- xlabel=xlabel, ylabel=ylabel,
- xdata=_xdata, ydata=_ydata)
- else:
- d.insert_image_yt(yt_plots, pos=(xpos, ypos),
- field=fields[index])
- d.axis_box_yt(yt_plots, pos=(xpos, ypos),
- bare_axes=bare_axes, xaxis_side=xaxis,
- yaxis_side=yaxis,
- xlabel=xlabel, ylabel=ylabel,
- xdata=_xdata, ydata=_ydata)
+ d.insert_image_yt(yt_plots[index], pos=(xpos, ypos),
+ field=fields[index])
+ d.axis_box_yt(yt_plots[index], pos=(xpos, ypos),
+ bare_axes=bare_axes, xaxis_side=xaxis,
+ yaxis_side=yaxis,
+ xlabel=xlabel, ylabel=ylabel,
+ xdata=_xdata, ydata=_ydata)
else:
d.insert_image(images[index], pos=(xpos,ypos))
d.axis_box(pos = (xpos, ypos),
@@ -1020,16 +1048,14 @@
if orientation != None:
if _yt:
- if plot_collection:
- d.colorbar_yt(yt_plots[index],
- pos=[xpos,ypos],
- shrink=shrink_cb,
- orientation=orientation)
- else:
- d.colorbar_yt(yt_plots, field=fields[index],
- pos=[xpos,ypos],
- shrink=shrink_cb,
- orientation=orientation)
+ # Set field if undefined
+ if fields[index] == None:
+ fields[index] = d.return_field(yt_plots[index])
+ d.colorbar_yt(yt_plots[index],
+ field=fields[index],
+ pos=[xpos,ypos],
+ shrink=shrink_cb,
+ orientation=orientation)
else:
d.colorbar(colorbars[index]["cmap"],
zrange=colorbars[index]["range"],
@@ -1077,13 +1103,16 @@
>>> mp = multiplot_yt(2,2,pc,savefig="yt",shrink_cb=0.9, bare_axes=False,
>>> yt_nocbar=False, margins=(0.5,0.5))
"""
+ # Determine whether the plots are organized in a PlotCollection,
+ # PlotWindow, or list of PlotWindows
if isinstance(plots, PlotCollection):
if len(plots.plots) < nrow*ncol:
raise RuntimeError("Number of plots in PlotCollection is less "\
"than nrow(%d) x ncol(%d)." % \
(len(plots.plots), nrow, ncol))
return
- figure = multiplot(ncol, nrow, yt_plots=plots.plots, **kwargs)
+ figure = multiplot(ncol, nrow, yt_plots=plots.plots,
+ plot_collection=True, **kwargs)
elif isinstance(plots, PlotWindow):
if fields == None:
fields = plots.fields
@@ -1093,6 +1122,16 @@
(len(fields), nrow, ncol))
return
figure = multiplot(ncol, nrow, yt_plots=plots, fields=fields, **kwargs)
+ elif isinstance(plots, list) and isinstance(plots[0], PlotWindow):
+ if len(plots) < nrow*ncol:
+ raise RuntimeError("Number of plots is less "\
+ "than nrow(%d) x ncol(%d)." % \
+ (len(fields), nrow, ncol))
+ return
+ figure = multiplot(ncol, nrow, yt_plots=plots, fields=fields, **kwargs)
+ else:
+ raise RuntimeError("Unknown plot type in multiplot_yt")
+ return
return figure
#=============================================================================
diff -r 6c19af205bde79dfc26fec7ada8c5f25a98c5200 -r 07827b57a7dac1623d7c5a294d8ebb50e420e3c3 yt/visualization/profile_plotter.py
--- a/yt/visualization/profile_plotter.py
+++ b/yt/visualization/profile_plotter.py
@@ -28,7 +28,9 @@
from .plot_window import WindowPlotMPL
from .base_plot_types import ImagePlotMPL
-from .plot_container import ImagePlotContainer
+from .plot_container import \
+ ImagePlotContainer, \
+ log_transform, linear_transform
from .image_writer import \
write_image, apply_colormap
from yt.data_objects.profiles import \
@@ -518,6 +520,7 @@
self.plot_title = {}
self.z_log = {}
self.z_title = {}
+ self._initfinished = False
if profile is None:
profile = create_profile(data_source,
@@ -531,6 +534,7 @@
figure_size, fontsize)
# This is a fallback, in case we forget.
self._setup_plots()
+ self._initfinished = True
def _get_field_title(self, field_z, profile):
pf = profile.data_source.pf
@@ -607,6 +611,10 @@
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 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])
@@ -688,6 +696,7 @@
def __init__(self, x_data, y_data, data,
x_scale, y_scale, z_scale, cmap,
zlim, size, fontsize, figure, axes, cax):
+ self._initfinished = False
self._draw_colorbar = True
self._draw_axes = True
self._cache_layout(size, fontsize)
@@ -709,6 +718,7 @@
figure, axes, cax)
self._init_image(x_data, y_data, data, x_scale, y_scale, z_scale,
zlim, cmap)
+ self._initfinished = True
def _init_image(self, x_data, y_data, image_data,
x_scale, y_scale, z_scale, zlim, cmap):
https://bitbucket.org/yt_analysis/yt/commits/3c91dfcd2162/
Changeset: 3c91dfcd2162
Branch: yt
User: jwise77
Date: 2013-12-03 13:11:27
Summary: Merging.
Affected #: 3 files
diff -r 07827b57a7dac1623d7c5a294d8ebb50e420e3c3 -r 3c91dfcd2162ed0e5de5ee49dfd2faf603af84a2 yt/visualization/plot_container.py
--- a/yt/visualization/plot_container.py
+++ b/yt/visualization/plot_container.py
@@ -183,9 +183,52 @@
self._colormaps[field] = cmap_name
return self
+ @invalidate_plot
def set_zlim(self, field, zmin, zmax, dynamic_range=None):
- # Left blank to be overriden in subclasses
- pass
+ """set the scale of the colormap
+
+ Parameters
+ ----------
+ field : string
+ the field to set a colormap scale
+ if field == 'all', applies to all plots.
+ zmin : float
+ the new minimum of the colormap scale. If 'min', will
+ set to the minimum value in the current view.
+ zmax : float
+ the new maximum of the colormap scale. If 'max', will
+ set to the maximum value in the current view.
+
+ Other Parameters
+ ----------------
+ dynamic_range : float (default: None)
+ The dynamic range of the image.
+ If zmin == None, will set zmin = zmax / dynamic_range
+ If zmax == None, will set zmax = zmin * dynamic_range
+ When dynamic_range is specified, defaults to setting
+ zmin = zmax / dynamic_range.
+
+ """
+ if field is 'all':
+ fields = self.plots.keys()
+ else:
+ fields = [field]
+ for field in fields:
+ myzmin = zmin
+ myzmax = zmax
+ if zmin == 'min':
+ myzmin = self.plots[field].image._A.min()
+ if zmax == 'max':
+ myzmax = self.plots[field].image._A.max()
+ if dynamic_range is not None:
+ if zmax is None:
+ myzmax = myzmin * dynamic_range
+ else:
+ myzmin = myzmax / dynamic_range
+
+ self.plots[field].zmin = myzmin
+ self.plots[field].zmax = myzmax
+ return self
def setup_callbacks(self):
# Left blank to be overriden in subclasses
diff -r 07827b57a7dac1623d7c5a294d8ebb50e420e3c3 -r 3c91dfcd2162ed0e5de5ee49dfd2faf603af84a2 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -730,53 +730,6 @@
self._plot_valid = True
- @invalidate_plot
- def set_zlim(self, field, zmin, zmax, dynamic_range=None):
- """set the scale of the colormap
-
- Parameters
- ----------
- field : string
- the field to set a colormap scale
- if field == 'all', applies to all plots.
- zmin : float
- the new minimum of the colormap scale. If 'min', will
- set to the minimum value in the current view.
- zmax : float
- the new maximum of the colormap scale. If 'max', will
- set to the maximum value in the current view.
-
- Other Parameters
- ----------------
- dynamic_range : float (default: None)
- The dynamic range of the image.
- If zmin == None, will set zmin = zmax / dynamic_range
- If zmax == None, will set zmax = zmin * dynamic_range
- When dynamic_range is specified, defaults to setting
- zmin = zmax / dynamic_range.
-
- """
- if field is 'all':
- fields = self.plots.keys()
- else:
- fields = [field]
- for field in fields:
- myzmin = zmin
- myzmax = zmax
- if zmin == 'min':
- myzmin = self.plots[field].image._A.min()
- if zmax == 'max':
- myzmax = self.plots[field].image._A.max()
- if dynamic_range is not None:
- if zmax is None:
- myzmax = myzmin * dynamic_range
- else:
- myzmin = myzmax / dynamic_range
-
- self.plots[field].zmin = myzmin
- self.plots[field].zmax = myzmax
- return self
-
def setup_callbacks(self):
for key in callback_registry:
ignored = ['PlotCallback','CoordAxesCallback','LabelCallback',
@@ -1195,6 +1148,11 @@
oblique=True, fontsize=fontsize)
self.set_axes_unit(axes_unit)
+ def _recreate_frb(self):
+ if self._frb is not None:
+ raise NotImplementedError
+ super(OffAxisProjectionPlot, self)._recreate_frb()
+
_metadata_template = """
%(pf)s<br><br>
diff -r 07827b57a7dac1623d7c5a294d8ebb50e420e3c3 -r 3c91dfcd2162ed0e5de5ee49dfd2faf603af84a2 yt/visualization/profile_plotter.py
--- a/yt/visualization/profile_plotter.py
+++ b/yt/visualization/profile_plotter.py
@@ -89,6 +89,21 @@
self[key] = figure.add_subplot(111)
return self[key]
+def sanitize_label(label, nprofiles):
+ label = ensure_list(label)
+
+ if len(label) == 1:
+ label = label * nprofiles
+
+ if len(label) != nprofiles:
+ raise RuntimeError("Number of labels must match number of profiles")
+
+ for l in label:
+ if l is not None and not isinstance(l, basestring):
+ raise RuntimeError("All labels must be None or a string")
+
+ return label
+
class ProfilePlot(object):
r"""
Create a 1d profile plot from a data source or from a list
@@ -197,9 +212,7 @@
else:
self.profiles = ensure_list(profiles)
- self.label = label
- if not isinstance(self.label, list):
- self.label = [self.label] * len(self.profiles)
+ self.label = sanitize_label(label, len(self.profiles))
self.plot_spec = plot_spec
if self.plot_spec is None:
@@ -308,7 +321,8 @@
axes.set_yscale(yscale)
axes.set_xlabel(xtitle)
axes.set_ylabel(ytitle)
- axes.legend(loc="best")
+ if any(self.label):
+ axes.legend(loc="best")
self._plot_valid = True
@classmethod
@@ -723,14 +737,13 @@
def _init_image(self, x_data, y_data, image_data,
x_scale, y_scale, z_scale, zlim, cmap):
"""Store output of imshow in image variable"""
-
if (z_scale == 'log'):
norm = matplotlib.colors.LogNorm(zlim[0], zlim[1])
elif (z_scale == 'linear'):
norm = matplotlib.colors.Normalize(zlim[0], zlim[1])
self.image = None
self.cb = None
- self.image = self.axes.pcolormesh(x_data, y_data, image_data,
+ self.image = self.axes.pcolormesh(x_data, y_data, image_data.T,
norm=norm,
cmap=cmap)
self.axes.set_xscale(x_scale)
https://bitbucket.org/yt_analysis/yt/commits/e7aebae21e2d/
Changeset: e7aebae21e2d
Branch: yt
User: jwise77
Date: 2013-12-03 13:52:46
Summary: Minor fixes for the eps_writer multiplot changes.
Affected #: 1 file
diff -r 3c91dfcd2162ed0e5de5ee49dfd2faf603af84a2 -r e7aebae21e2dad92c04e96aa052575013c1df18b yt/visualization/eps_writer.py
--- a/yt/visualization/eps_writer.py
+++ b/yt/visualization/eps_writer.py
@@ -340,7 +340,7 @@
if ylabel != None:
_ylabel = ylabel
else:
- _xlabel = plot[k].axes.get_ylabel()
+ _ylabel = plot[k].axes.get_ylabel()
if tickcolor == None:
_tickcolor = None
else:
@@ -453,7 +453,8 @@
plot.refresh()
_p1 = plot.plots[self.field].figure
# hack to account for non-square display ratios (not sure why)
- shift = 12.0 / 340
+ if isinstance(plot, PlotWindow):
+ shift = 12.0 / 340
elif isinstance(plot, ProfilePlot):
plot._redraw_image()
# Remove colorbar
https://bitbucket.org/yt_analysis/yt/commits/b816017ad1f9/
Changeset: b816017ad1f9
Branch: yt
User: jwise77
Date: 2013-12-03 15:26:28
Summary: Using tuples in plot isinstance calls.
Affected #: 1 file
diff -r e7aebae21e2dad92c04e96aa052575013c1df18b -r b816017ad1f9db1f5cfe6ced43ed1b64d76c24d2 yt/visualization/eps_writer.py
--- a/yt/visualization/eps_writer.py
+++ b/yt/visualization/eps_writer.py
@@ -285,11 +285,11 @@
>>> d.axis_box_yt(p)
>>> d.save_fig()
"""
- if isinstance(plot, PlotWindow) or isinstance(plot, PhasePlot):
+ if isinstance(plot, (PlotWindow, PhasePlot)):
plot.refresh()
else:
plot._redraw_image()
- if isinstance(plot, VMPlot) or isinstance(plot, PlotWindow):
+ if isinstance(plot, (VMPlot, PlotWindow)):
if isinstance(plot, PlotWindow):
data = plot._frb
width = plot.width[0]
@@ -441,7 +441,7 @@
plot.colorbar = None
plot._redraw_image()
_p1 = plot._figure
- elif isinstance(plot, PlotWindow) or isinstance(plot, PhasePlot):
+ elif isinstance(plot, (PlotWindow, PhasePlot)):
self.field = field
if self.field == None:
self.field = plot.plots.keys()[0]
@@ -622,7 +622,7 @@
_cmap = None
if field != None:
self.field = field
- if isinstance(plot, PlotWindow) or isinstance(plot, PhasePlot):
+ if isinstance(plot, (PlotWindow, PhasePlot)):
_cmap = plot._colormaps[self.field]
else:
if plot.cmap != None:
@@ -636,7 +636,7 @@
_zlabel = _zlabel.replace("_","\;")
_zlog = plot.log_field
_zrange = (plot.norm.vmin, plot.norm.vmax)
- elif isinstance(plot, PlotWindow) or isinstance(plot, PhasePlot):
+ elif isinstance(plot, (PlotWindow, PhasePlot)):
proj = plot._plot_type.endswith("Projection") and \
plot.data_source.weight_field == None
if isinstance(plot, PlotWindow):
https://bitbucket.org/yt_analysis/yt/commits/762ef5f55246/
Changeset: 762ef5f55246
Branch: yt
User: jwise77
Date: 2013-12-03 20:32:46
Summary: Forgot to floor the figure size.
Affected #: 1 file
diff -r b816017ad1f9db1f5cfe6ced43ed1b64d76c24d2 -r 762ef5f552468ccc7de6c8ace46af57c70398c07 yt/visualization/eps_writer.py
--- a/yt/visualization/eps_writer.py
+++ b/yt/visualization/eps_writer.py
@@ -468,7 +468,7 @@
_p1.set_facecolor('w') # set background color
figure_canvas = FigureCanvasAgg(_p1)
figure_canvas.draw()
- size = _p1.get_size_inches() * _p1.dpi
+ size = (_p1.get_size_inches() * _p1.dpi).astype('int')
image = pyx.bitmap.image(size[0], size[1], "RGB",
figure_canvas.tostring_rgb())
#figure_canvas.print_png('test.png')
https://bitbucket.org/yt_analysis/yt/commits/235c3b3d90ae/
Changeset: 235c3b3d90ae
Branch: yt
User: MatthewTurk
Date: 2013-12-04 21:54:34
Summary: Merged in jwise77/yt (pull request #661)
eps_writer updates (PhasePlot compatibility and multiplot updates)
Affected #: 2 files
diff -r efb0f897834333da7e282715604b133f1c81abec -r 235c3b3d90ae5030d7631106ccdab3e2276358cf yt/visualization/eps_writer.py
--- a/yt/visualization/eps_writer.py
+++ b/yt/visualization/eps_writer.py
@@ -26,7 +26,9 @@
from .plot_types import \
VMPlot, \
ProfilePlot
+from .plot_collection import PlotCollection
from .plot_window import PlotWindow
+from .profile_plotter import PhasePlot
from .plot_modifications import get_smallest_appropriate_unit
class DualEPS(object):
@@ -57,6 +59,14 @@
#=============================================================================
+ def return_field(self, plot):
+ if isinstance(plot, PlotWindow) or isinstance(plot, PhasePlot):
+ return plot.plots.keys()[0]
+ else:
+ return None
+
+#=============================================================================
+
def axis_box(self, xrange=(0,1), yrange=(0,1), xlabel="", ylabel="",
xlog=False, ylog=False, xdata=None, ydata=None,
tickcolor=None, bare_axes=False,
@@ -275,18 +285,17 @@
>>> d.axis_box_yt(p)
>>> d.save_fig()
"""
- if isinstance(plot, PlotWindow):
+ if isinstance(plot, (PlotWindow, PhasePlot)):
plot.refresh()
- width = plot.width[0]
else:
plot._redraw_image()
- if isinstance(plot, VMPlot):
- width = plot.width
- if isinstance(plot, VMPlot) or isinstance(plot, PlotWindow):
+ if isinstance(plot, (VMPlot, PlotWindow)):
if isinstance(plot, PlotWindow):
data = plot._frb
+ width = plot.width[0]
else:
data = plot.data
+ width = plot.width
if units == None:
units = get_smallest_appropriate_unit(width, plot.pf)
_xrange = (0, width * plot.pf[units])
@@ -314,6 +323,26 @@
_ylabel = 'Image y (%s)' % (units)
if tickcolor == None:
_tickcolor = pyx.color.cmyk.white
+ elif isinstance(plot, PhasePlot):
+ k = plot.plots.keys()[0]
+ _xrange = plot[k].axes.get_xlim()
+ _yrange = plot[k].axes.get_ylim()
+ _xlog = plot.profile.x_log
+ _ylog = plot.profile.y_log
+ if bare_axes:
+ _xlabel = ""
+ _ylabel = ""
+ else:
+ if xlabel != None:
+ _xlabel = xlabel
+ else:
+ _xlabel = plot[k].axes.get_xlabel()
+ if ylabel != None:
+ _ylabel = ylabel
+ else:
+ _ylabel = plot[k].axes.get_ylabel()
+ if tickcolor == None:
+ _tickcolor = None
else:
_xrange = plot._axes.get_xlim()
_yrange = plot._axes.get_ylim()
@@ -412,7 +441,7 @@
plot.colorbar = None
plot._redraw_image()
_p1 = plot._figure
- elif isinstance(plot, PlotWindow):
+ elif isinstance(plot, (PlotWindow, PhasePlot)):
self.field = field
if self.field == None:
self.field = plot.plots.keys()[0]
@@ -424,18 +453,22 @@
plot.refresh()
_p1 = plot.plots[self.field].figure
# hack to account for non-square display ratios (not sure why)
- shift = 12.0 / 340
+ if isinstance(plot, PlotWindow):
+ shift = 12.0 / 340
elif isinstance(plot, ProfilePlot):
plot._redraw_image()
# Remove colorbar
_p1 = plot._figure
_p1.delaxes(_p1.axes[1])
+ else:
+ raise RuntimeError("Unknown plot type")
+
_p1.axes[0].set_axis_off() # remove axes
_p1.axes[0].set_position([-shift,0,1,1]) # rescale figure
_p1.set_facecolor('w') # set background color
figure_canvas = FigureCanvasAgg(_p1)
figure_canvas.draw()
- size = _p1.get_size_inches() * _p1.dpi
+ size = (_p1.get_size_inches() * _p1.dpi).astype('int')
image = pyx.bitmap.image(size[0], size[1], "RGB",
figure_canvas.tostring_rgb())
#figure_canvas.print_png('test.png')
@@ -567,7 +600,7 @@
#=============================================================================
- def colorbar_yt(self, plot, **kwargs):
+ def colorbar_yt(self, plot, field=None, **kwargs):
r"""Wrapper around DualEPS.colorbar to take information from a yt plot.
Accepts all parameters that DualEPS.colorbar takes.
@@ -587,7 +620,9 @@
>>> d.save_fig()
"""
_cmap = None
- if isinstance(plot, PlotWindow):
+ if field != None:
+ self.field = field
+ if isinstance(plot, (PlotWindow, PhasePlot)):
_cmap = plot._colormaps[self.field]
else:
if plot.cmap != None:
@@ -601,10 +636,13 @@
_zlabel = _zlabel.replace("_","\;")
_zlog = plot.log_field
_zrange = (plot.norm.vmin, plot.norm.vmax)
- elif isinstance(plot, PlotWindow):
+ elif isinstance(plot, (PlotWindow, PhasePlot)):
proj = plot._plot_type.endswith("Projection") and \
plot.data_source.weight_field == None
- _zlabel = plot.pf.field_info[self.field].get_label(proj)
+ if isinstance(plot, PlotWindow):
+ _zlabel = plot.pf.field_info[self.field].get_label(proj)
+ else:
+ _zlabel = plot.data_source.pf.field_info[self.field].get_label(proj)
_zlabel = _zlabel.replace("_","\;")
_zlog = plot.get_log(self.field)[self.field]
if plot.plots[self.field].zmin == None:
@@ -783,13 +821,13 @@
#=============================================================================
#=============================================================================
-def multiplot(ncol, nrow, yt_plots=None, images=None, xranges=None,
- yranges=None, xlabels=None, ylabels=None,
+def multiplot(ncol, nrow, yt_plots=None, fields=None, images=None,
+ xranges=None, yranges=None, xlabels=None, ylabels=None,
xdata=None, ydata=None, colorbars=None,
shrink_cb=0.95, figsize=(8,8), margins=(0,0), titles=None,
savefig=None, format="eps", yt_nocbar=False, bare_axes=False,
xaxis_flags=None, yaxis_flags=None,
- cb_flags=None):
+ cb_flags=None, cb_location=None, plot_collection=False):
r"""Convenience routine to create a multi-panel figure from yt plots or
JPEGs. The images are first placed from the origin, and then
bottom-to-top and left-to-right.
@@ -834,6 +872,11 @@
axes.
cb_flags : list of booleans
Flags for each plot to have a colorbar or not.
+ cb_location : list of strings
+ Strings to control the location of the colorbar (left, right,
+ top, bottom)
+ plot_collection : boolean
+ Set to true to yt_plots is a PlotCollection
Examples
--------
@@ -858,8 +901,9 @@
yt plots.
"""
# Error check
+ npanels = ncol*nrow
if images != None:
- if len(images) != ncol*nrow:
+ if len(images) != npanels:
raise RuntimeError("Number of images (%d) doesn't match nrow(%d)"\
" x ncol(%d)." % (len(images), nrow, ncol))
return
@@ -872,21 +916,23 @@
_yt = True
else:
_yt = False
+ if fields == None:
+ fields = [None] * npanels
# If no ranges or labels given and given only images, fill them in.
if not _yt:
if xranges is None:
xranges = []
- for i in range(nrow*ncol): xranges.append((0,1))
+ for i in range(npanels): xranges.append((0,1))
if yranges is None:
yranges = []
- for i in range(nrow*ncol): yranges.append((0,1))
+ for i in range(npanels): yranges.append((0,1))
if xlabels is None:
xlabels = []
- for i in range(nrow*ncol): xlabels.append("")
+ for i in range(npanels): xlabels.append("")
if ylabels is None:
ylabels = []
- for i in range(nrow*ncol): ylabels.append("")
+ for i in range(npanels): ylabels.append("")
d = DualEPS(figsize=figsize)
count = 0
@@ -930,7 +976,8 @@
ylabel = ylabels[j]
else:
ylabel = None
- d.insert_image_yt(yt_plots[index], pos=(xpos, ypos))
+ d.insert_image_yt(yt_plots[index], pos=(xpos, ypos),
+ field=fields[index])
d.axis_box_yt(yt_plots[index], pos=(xpos, ypos),
bare_axes=bare_axes, xaxis_side=xaxis,
yaxis_side=yaxis,
@@ -964,32 +1011,49 @@
if cb_flags != None:
if cb_flags[index] == False:
continue
- if ncol == 1:
- orientation = "right"
+ if cb_location == None:
+ if ncol == 1:
+ orientation = "right"
+ elif i == 0:
+ orientation = "left"
+ elif i+1 == ncol:
+ orientation = "right"
+ elif j == 0:
+ orientation = "bottom"
+ elif j+1 == nrow:
+ orientation = "top"
+ else:
+ orientation = None # Marker for interior plot
+ else:
+ if fields[index] not in cb_location.keys():
+ raise RuntimeError("%s not found in cb_location dict" %
+ fields[index])
+ return
+ orientation = cb_location[fields[index]]
+ if orientation == "right":
xpos = bbox[1]
ypos = ypos0
- elif j == 0:
- orientation = "bottom"
+ elif orientation == "left":
+ xpos = bbox[0]
+ ypos = ypos0
+ elif orientation == "bottom":
ypos = bbox[2]
xpos = xpos0
- elif i == 0:
- orientation = "left"
- xpos = bbox[0]
- ypos = ypos0
- elif i+1 == ncol:
- orientation = "right"
- xpos = bbox[1]
- ypos = ypos0
- elif j+1 == nrow:
- orientation = "top"
+ elif orientation == "top":
ypos = bbox[3]
xpos = xpos0
else:
+ mylog.warning("Unknown colorbar location %s. "
+ "No colorbar displayed." % orientation)
orientation = None # Marker for interior plot
if orientation != None:
if _yt:
+ # Set field if undefined
+ if fields[index] == None:
+ fields[index] = d.return_field(yt_plots[index])
d.colorbar_yt(yt_plots[index],
+ field=fields[index],
pos=[xpos,ypos],
shrink=shrink_cb,
orientation=orientation)
@@ -1009,8 +1073,8 @@
#=============================================================================
-def multiplot_yt(ncol, nrow, plot_col, **kwargs):
- r"""Wrapper for multiplot that takes a yt PlotCollection.
+def multiplot_yt(ncol, nrow, plots, fields=None, **kwargs):
+ r"""Wrapper for multiplot that takes a yt PlotWindow or PlotCollection.
Accepts all parameters used in multiplot.
@@ -1020,8 +1084,8 @@
Number of columns in the figure.
nrow : integer
Number of rows in the figure.
- plot_col : `PlotCollection`
- yt PlotCollection that has the plots to be used.
+ plots : `PlotCollection` or `PlotWindow`
+ yt PlotCollection or PlotWindow that has the plots to be used.
Examples
--------
@@ -1040,18 +1104,42 @@
>>> mp = multiplot_yt(2,2,pc,savefig="yt",shrink_cb=0.9, bare_axes=False,
>>> yt_nocbar=False, margins=(0.5,0.5))
"""
- if len(plot_col.plots) < nrow*ncol:
- raise RuntimeError("Number of plots in PlotCollection is less "\
- "than nrow(%d) x ncol(%d)." % \
- (len(plot_col.plots), nrow, ncol))
+ # Determine whether the plots are organized in a PlotCollection,
+ # PlotWindow, or list of PlotWindows
+ if isinstance(plots, PlotCollection):
+ if len(plots.plots) < nrow*ncol:
+ raise RuntimeError("Number of plots in PlotCollection is less "\
+ "than nrow(%d) x ncol(%d)." % \
+ (len(plots.plots), nrow, ncol))
+ return
+ figure = multiplot(ncol, nrow, yt_plots=plots.plots,
+ plot_collection=True, **kwargs)
+ elif isinstance(plots, PlotWindow):
+ if fields == None:
+ fields = plots.fields
+ if len(fields) < nrow*ncol:
+ raise RuntimeError("Number of plots is less "\
+ "than nrow(%d) x ncol(%d)." % \
+ (len(fields), nrow, ncol))
+ return
+ figure = multiplot(ncol, nrow, yt_plots=plots, fields=fields, **kwargs)
+ elif isinstance(plots, list) and isinstance(plots[0], PlotWindow):
+ if len(plots) < nrow*ncol:
+ raise RuntimeError("Number of plots is less "\
+ "than nrow(%d) x ncol(%d)." % \
+ (len(fields), nrow, ncol))
+ return
+ figure = multiplot(ncol, nrow, yt_plots=plots, fields=fields, **kwargs)
+ else:
+ raise RuntimeError("Unknown plot type in multiplot_yt")
return
- figure = multiplot(ncol, nrow, yt_plots=plot_col.plots, **kwargs)
return figure
#=============================================================================
-def single_plot(plot, figsize=(12,12), cb_orient="right", bare_axes=False,
- savefig=None, colorbar=True, file_format='eps', **kwargs):
+def single_plot(plot, field=None, figsize=(12,12), cb_orient="right",
+ bare_axes=False, savefig=None, colorbar=True,
+ file_format='eps', **kwargs):
r"""Wrapper for DualEPS routines to create a figure directy from a yt
plot. Calls insert_image_yt, axis_box_yt, and colorbar_yt.
@@ -1080,7 +1168,7 @@
>>> single_plot(p, savefig="figure1")
"""
d = DualEPS(figsize=figsize)
- d.insert_image_yt(plot)
+ d.insert_image_yt(plot, field=field)
d.axis_box_yt(plot, bare_axes=bare_axes, **kwargs)
if colorbar:
d.colorbar_yt(plot, orientation=cb_orient)
diff -r efb0f897834333da7e282715604b133f1c81abec -r 235c3b3d90ae5030d7631106ccdab3e2276358cf yt/visualization/profile_plotter.py
--- a/yt/visualization/profile_plotter.py
+++ b/yt/visualization/profile_plotter.py
@@ -28,7 +28,9 @@
from .plot_window import WindowPlotMPL
from .base_plot_types import ImagePlotMPL
-from .plot_container import ImagePlotContainer
+from .plot_container import \
+ ImagePlotContainer, \
+ log_transform, linear_transform
from .image_writer import \
write_image, apply_colormap
from yt.data_objects.profiles import \
@@ -532,6 +534,7 @@
self.plot_title = {}
self.z_log = {}
self.z_title = {}
+ self._initfinished = False
if profile is None:
profile = create_profile(data_source,
@@ -545,6 +548,7 @@
figure_size, fontsize)
# This is a fallback, in case we forget.
self._setup_plots()
+ self._initfinished = True
def _get_field_title(self, field_z, profile):
pf = profile.data_source.pf
@@ -621,6 +625,10 @@
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 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])
@@ -702,6 +710,7 @@
def __init__(self, x_data, y_data, data,
x_scale, y_scale, z_scale, cmap,
zlim, size, fontsize, figure, axes, cax):
+ self._initfinished = False
self._draw_colorbar = True
self._draw_axes = True
self._cache_layout(size, fontsize)
@@ -723,6 +732,7 @@
figure, axes, cax)
self._init_image(x_data, y_data, data, x_scale, y_scale, z_scale,
zlim, cmap)
+ self._initfinished = True
def _init_image(self, x_data, y_data, image_data,
x_scale, y_scale, z_scale, zlim, cmap):
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