[yt-svn] commit/yt: 8 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Sep 12 12:52:24 PDT 2013
8 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/91473dc1d8fe/
Changeset: 91473dc1d8fe
Branch: yt
User: ngoldbaum
Date: 2013-09-09 08:41:31
Summary: Making WindowPlotMPL axes and colorbars toggleable.
Affected #: 1 file
diff -r b3b28b859b0e9d6c7699fb70768dbe08bd8a4d5a -r 91473dc1d8fece63a0d7b7eb20b93d1e876d922b yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -1789,7 +1789,16 @@
def __init__(
self, data, cbname, cmap, extent, aspect, zlim, size, fontsize,
figure, axes, cax):
- fsize, axrect, caxrect = self._get_best_layout(size, fontsize)
+ self._draw_colorbar = True
+ self._draw_axes = True
+ self._cache_layout(size, fontsize)
+
+ # Make room for a colorbar
+ self.input_size = size
+ self.fsize = [size[0] + self._cbar_inches[self._draw_colorbar], size[1]]
+
+ # Compute layout
+ axrect, caxrect = self._get_best_layout(fontsize)
if np.any(np.array(axrect) < 0):
mylog.warning('The axis ratio of the requested plot is very narrow. '
'There is a good chance the plot will not look very good, '
@@ -1798,7 +1807,7 @@
axrect = (0.07, 0.10, 0.80, 0.80)
caxrect = (0.87, 0.10, 0.04, 0.80)
ImagePlotMPL.__init__(
- self, fsize, axrect, caxrect, zlim, figure, axes, cax)
+ self, self.fsize, axrect, caxrect, zlim, figure, axes, cax)
self._init_image(data, cbname, cmap, extent, aspect)
self.image.axes.ticklabel_format(scilimits=(-2,3))
if cbname == 'linear':
@@ -1806,31 +1815,74 @@
self.cb.formatter.set_powerlimits((-2,3))
self.cb.update_ticks()
- def _get_best_layout(self, size, fontsize=18):
- aspect = 1.0*size[0]/size[1]
- fontscale = fontsize / 18.0
+ def _toggle_axes(self, choice):
+ self._draw_axes = choice
+ self.axes.get_xaxis().set_visible(choice)
+ self.axes.get_yaxis().set_visible(choice)
+ axrect, caxrect = self._get_best_layout()
+ self.axes.set_position(axrect)
+ self.cax.set_position(caxrect)
- # add room for a colorbar
- cbar_inches = fontscale*0.7
- newsize = [size[0] + cbar_inches, size[1]]
+ def _toggle_colorbar(self, choice):
+ self._draw_colorbar = choice
+ self.cax.set_visible(choice)
+ self.fsize = [self.input_size[0] + self._cbar_inches[choice], self.input_size[1]]
+ axrect, caxrect = self._get_best_layout()
+ self.axes.set_position(axrect)
+ self.cax.set_position(caxrect)
+
+ def hide_axes(self):
+ self._toggle_axes(False)
+ return self
+
+ def show_axes(self):
+ self._toggle_axes(True)
+ return self
+
+ def hide_colorbar(self):
+ self._toggle_colorbar(False)
+ return self
+
+ def show_colorbar(self):
+ self._toggle_colorbar(True)
+ return self
+
+ def _cache_layout(self, size, fontsize):
+ self._cbar_inches = {}
+ self._text_buffx = {}
+ self._text_bottomy = {}
+ self._text_topy = {}
+
+ self._aspect = 1.0*size[0]/size[1]
+ self._fontscale = fontsize / 18.0
+
+ # Leave room for a colorbar, if we are drawing it.
+ self._cbar_inches[True] = self._fontscale*0.7
+ self._cbar_inches[False] = 0
# add buffers for text, and a bit of whitespace on top
- text_buffx = fontscale * 1.0/(newsize[0])
- text_bottomy = fontscale * 0.7/size[1]
- text_topy = fontscale * 0.3/size[1]
+ self._text_buffx[True] = self._fontscale * 1.0/(size[0])
+ self._text_bottomy[True] = self._fontscale * 0.7/size[1]
+ self._text_topy[True] = self._fontscale * 0.3/size[1]
+ # No buffer for text if we're not drawing axes
+ self._text_buffx[False] = 0
+ self._text_bottomy[False] = 0
+ self._text_topy[False] = 0
+
+ def _get_best_layout(self, fontsize=18):
# calculate how much room the colorbar takes
- cbar_frac = cbar_inches/newsize[0]
+ cbar_frac = self._cbar_inches[self._draw_colorbar]/self.fsize[0]
# Calculate y fraction, then use to make x fraction.
- yfrac = 1.0-text_bottomy-text_topy
- ysize = yfrac*size[1]
- xsize = aspect*ysize
- xfrac = xsize/newsize[0]
+ yfrac = 1.0-self._text_bottomy[self._draw_axes]-self._text_topy[self._draw_axes]
+ ysize = yfrac*self.fsize[1]
+ xsize = self._aspect*ysize
+ xfrac = xsize/self.fsize[0]
# Now make sure it all fits!
- xbig = xfrac + text_buffx + 2.0*cbar_frac
- ybig = yfrac + text_bottomy + text_topy
+ xbig = xfrac + self._text_buffx[self._draw_axes] + 2.0*cbar_frac
+ ybig = yfrac + self._text_bottomy[self._draw_axes] + self._text_topy[self._draw_axes]
if xbig > 1:
xsize /= xbig
@@ -1838,9 +1890,20 @@
if ybig > 1:
xsize /= ybig
ysize /= ybig
- xfrac = xsize/newsize[0]
- yfrac = ysize/newsize[1]
+ xfrac = xsize/self.fsize[0]
+ yfrac = ysize/self.fsize[1]
- axrect = (text_buffx, text_bottomy, xfrac, yfrac )
- caxrect = (text_buffx+xfrac, text_bottomy, cbar_frac/4., yfrac )
- return newsize, axrect, caxrect
+ axrect = (
+ self._text_buffx[self._draw_axes],
+ self._text_bottomy[self._draw_axes],
+ xfrac,
+ yfrac
+ )
+
+ caxrect = (
+ self._text_buffx[self._draw_axes]+xfrac,
+ self._text_bottomy[self._draw_axes],
+ cbar_frac/4.,
+ yfrac
+ )
+ return axrect, caxrect
https://bitbucket.org/yt_analysis/yt/commits/e54809b27344/
Changeset: e54809b27344
Branch: yt
User: ngoldbaum
Date: 2013-09-09 08:49:44
Summary: Sanitize field names, which sometimes contain whitespace. Closes #646
Affected #: 1 file
diff -r 91473dc1d8fece63a0d7b7eb20b93d1e876d922b -r e54809b27344c746fe43f87170bb7b506bdcb7fd yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -1083,15 +1083,15 @@
weight = None
type = self._plot_type
if type in ['Projection','OffAxisProjection']:
- weight = self.data_source.weight_field
+ weight = self.data_source.weight_field.replace(' ', '_')
if 'Cutting' in self.data_source.__class__.__name__:
type = 'OffAxisSlice'
for k, v in self.plots.iteritems():
if axis:
- n = "%s_%s_%s_%s" % (name, type, axis, k)
+ n = "%s_%s_%s_%s" % (name, type, axis, k.replace(' ', '_'))
else:
# for cutting planes
- n = "%s_%s_%s" % (name, type, k)
+ n = "%s_%s_%s" % (name, type, k.replace(' ', '_'))
if weight:
n += "_%s" % (weight)
names.append(v.save(n,mpl_kwargs))
https://bitbucket.org/yt_analysis/yt/commits/9f6b4ebc4e5d/
Changeset: 9f6b4ebc4e5d
Branch: yt
User: ngoldbaum
Date: 2013-09-09 09:01:43
Summary: Fixing unit test errors.
Affected #: 1 file
diff -r e54809b27344c746fe43f87170bb7b506bdcb7fd -r 9f6b4ebc4e5d8e276e4fad4ddda7f768a183a264 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -1083,7 +1083,9 @@
weight = None
type = self._plot_type
if type in ['Projection','OffAxisProjection']:
- weight = self.data_source.weight_field.replace(' ', '_')
+ weight = self.data_source.weight_field
+ if weight is not None:
+ weight = weight.replace(' ', '_')
if 'Cutting' in self.data_source.__class__.__name__:
type = 'OffAxisSlice'
for k, v in self.plots.iteritems():
https://bitbucket.org/yt_analysis/yt/commits/b45c104e0170/
Changeset: b45c104e0170
Branch: yt
User: ngoldbaum
Date: 2013-09-09 09:44:31
Summary: Fixing some (all?) answer tests.
Affected #: 1 file
diff -r 9f6b4ebc4e5d8e276e4fad4ddda7f768a183a264 -r b45c104e01704f2218c27865496edc3dc0075417 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -1863,7 +1863,7 @@
self._cbar_inches[False] = 0
# add buffers for text, and a bit of whitespace on top
- self._text_buffx[True] = self._fontscale * 1.0/(size[0])
+ self._text_buffx[True] = self._fontscale * 1.0/(size[0] + self._cbar_inches[True])
self._text_bottomy[True] = self._fontscale * 0.7/size[1]
self._text_topy[True] = self._fontscale * 0.3/size[1]
https://bitbucket.org/yt_analysis/yt/commits/9651b830f049/
Changeset: 9651b830f049
Branch: yt
User: MatthewTurk
Date: 2013-09-09 20:32:33
Summary: Merging in pull request 592.
Affected #: 1 file
diff -r 079e456c38a87676472a458210077e2be325dc85 -r 9651b830f049931de6fa3813eb2ee2e15bfdb17c yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -1084,14 +1084,16 @@
type = self._plot_type
if type in ['Projection','OffAxisProjection']:
weight = self.data_source.weight_field
+ if weight is not None:
+ weight = weight.replace(' ', '_')
if 'Cutting' in self.data_source.__class__.__name__:
type = 'OffAxisSlice'
for k, v in self.plots.iteritems():
if axis:
- n = "%s_%s_%s_%s" % (name, type, axis, k)
+ n = "%s_%s_%s_%s" % (name, type, axis, k.replace(' ', '_'))
else:
# for cutting planes
- n = "%s_%s_%s" % (name, type, k)
+ n = "%s_%s_%s" % (name, type, k.replace(' ', '_'))
if weight:
n += "_%s" % (weight)
names.append(v.save(n,mpl_kwargs))
@@ -1789,7 +1791,16 @@
def __init__(
self, data, cbname, cmap, extent, aspect, zlim, size, fontsize,
figure, axes, cax):
- fsize, axrect, caxrect = self._get_best_layout(size, fontsize)
+ self._draw_colorbar = True
+ self._draw_axes = True
+ self._cache_layout(size, fontsize)
+
+ # Make room for a colorbar
+ self.input_size = size
+ self.fsize = [size[0] + self._cbar_inches[self._draw_colorbar], size[1]]
+
+ # Compute layout
+ axrect, caxrect = self._get_best_layout(fontsize)
if np.any(np.array(axrect) < 0):
mylog.warning('The axis ratio of the requested plot is very narrow. '
'There is a good chance the plot will not look very good, '
@@ -1798,7 +1809,7 @@
axrect = (0.07, 0.10, 0.80, 0.80)
caxrect = (0.87, 0.10, 0.04, 0.80)
ImagePlotMPL.__init__(
- self, fsize, axrect, caxrect, zlim, figure, axes, cax)
+ self, self.fsize, axrect, caxrect, zlim, figure, axes, cax)
self._init_image(data, cbname, cmap, extent, aspect)
self.image.axes.ticklabel_format(scilimits=(-2,3))
if cbname == 'linear':
@@ -1806,31 +1817,74 @@
self.cb.formatter.set_powerlimits((-2,3))
self.cb.update_ticks()
- def _get_best_layout(self, size, fontsize=18):
- aspect = 1.0*size[0]/size[1]
- fontscale = fontsize / 18.0
+ def _toggle_axes(self, choice):
+ self._draw_axes = choice
+ self.axes.get_xaxis().set_visible(choice)
+ self.axes.get_yaxis().set_visible(choice)
+ axrect, caxrect = self._get_best_layout()
+ self.axes.set_position(axrect)
+ self.cax.set_position(caxrect)
- # add room for a colorbar
- cbar_inches = fontscale*0.7
- newsize = [size[0] + cbar_inches, size[1]]
+ def _toggle_colorbar(self, choice):
+ self._draw_colorbar = choice
+ self.cax.set_visible(choice)
+ self.fsize = [self.input_size[0] + self._cbar_inches[choice], self.input_size[1]]
+ axrect, caxrect = self._get_best_layout()
+ self.axes.set_position(axrect)
+ self.cax.set_position(caxrect)
+
+ def hide_axes(self):
+ self._toggle_axes(False)
+ return self
+
+ def show_axes(self):
+ self._toggle_axes(True)
+ return self
+
+ def hide_colorbar(self):
+ self._toggle_colorbar(False)
+ return self
+
+ def show_colorbar(self):
+ self._toggle_colorbar(True)
+ return self
+
+ def _cache_layout(self, size, fontsize):
+ self._cbar_inches = {}
+ self._text_buffx = {}
+ self._text_bottomy = {}
+ self._text_topy = {}
+
+ self._aspect = 1.0*size[0]/size[1]
+ self._fontscale = fontsize / 18.0
+
+ # Leave room for a colorbar, if we are drawing it.
+ self._cbar_inches[True] = self._fontscale*0.7
+ self._cbar_inches[False] = 0
# add buffers for text, and a bit of whitespace on top
- text_buffx = fontscale * 1.0/(newsize[0])
- text_bottomy = fontscale * 0.7/size[1]
- text_topy = fontscale * 0.3/size[1]
+ self._text_buffx[True] = self._fontscale * 1.0/(size[0] + self._cbar_inches[True])
+ self._text_bottomy[True] = self._fontscale * 0.7/size[1]
+ self._text_topy[True] = self._fontscale * 0.3/size[1]
+ # No buffer for text if we're not drawing axes
+ self._text_buffx[False] = 0
+ self._text_bottomy[False] = 0
+ self._text_topy[False] = 0
+
+ def _get_best_layout(self, fontsize=18):
# calculate how much room the colorbar takes
- cbar_frac = cbar_inches/newsize[0]
+ cbar_frac = self._cbar_inches[self._draw_colorbar]/self.fsize[0]
# Calculate y fraction, then use to make x fraction.
- yfrac = 1.0-text_bottomy-text_topy
- ysize = yfrac*size[1]
- xsize = aspect*ysize
- xfrac = xsize/newsize[0]
+ yfrac = 1.0-self._text_bottomy[self._draw_axes]-self._text_topy[self._draw_axes]
+ ysize = yfrac*self.fsize[1]
+ xsize = self._aspect*ysize
+ xfrac = xsize/self.fsize[0]
# Now make sure it all fits!
- xbig = xfrac + text_buffx + 2.0*cbar_frac
- ybig = yfrac + text_bottomy + text_topy
+ xbig = xfrac + self._text_buffx[self._draw_axes] + 2.0*cbar_frac
+ ybig = yfrac + self._text_bottomy[self._draw_axes] + self._text_topy[self._draw_axes]
if xbig > 1:
xsize /= xbig
@@ -1838,9 +1892,20 @@
if ybig > 1:
xsize /= ybig
ysize /= ybig
- xfrac = xsize/newsize[0]
- yfrac = ysize/newsize[1]
+ xfrac = xsize/self.fsize[0]
+ yfrac = ysize/self.fsize[1]
- axrect = (text_buffx, text_bottomy, xfrac, yfrac )
- caxrect = (text_buffx+xfrac, text_bottomy, cbar_frac/4., yfrac )
- return newsize, axrect, caxrect
+ axrect = (
+ self._text_buffx[self._draw_axes],
+ self._text_bottomy[self._draw_axes],
+ xfrac,
+ yfrac
+ )
+
+ caxrect = (
+ self._text_buffx[self._draw_axes]+xfrac,
+ self._text_bottomy[self._draw_axes],
+ cbar_frac/4.,
+ yfrac
+ )
+ return axrect, caxrect
https://bitbucket.org/yt_analysis/yt/commits/0b52b74efc3c/
Changeset: 0b52b74efc3c
Branch: yt
User: MatthewTurk
Date: 2013-09-10 14:59:34
Summary: Adding alternate data source for annotate_contour
Affected #: 1 file
diff -r 9651b830f049931de6fa3813eb2ee2e15bfdb17c -r 0b52b74efc3c0c8b4da64b86654ac9c669680635 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -232,17 +232,20 @@
class ContourCallback(PlotCallback):
"""
annotate_contour(field, ncont=5, factor=4, take_log=None, clim=None,
- plot_args=None, label=False, label_args=None):
+ plot_args=None, label=False, label_args=None,
+ data_source=None):
Add contours in *field* to the plot. *ncont* governs the number of
contours generated, *factor* governs the number of points used in the
interpolation, *take_log* governs how it is contoured and *clim* gives
- the (upper, lower) limits for contouring.
+ the (upper, lower) limits for contouring. An alternate data source can be
+ specified with *data_source*, but by default the plot being annotated will
+ be queried.
"""
_type_name = "contour"
def __init__(self, field, ncont=5, factor=4, clim=None,
plot_args = None, label = False, take_log = None,
- label_args = None):
+ label_args = None, data_source = None):
PlotCallback.__init__(self)
self.ncont = ncont
self.field = field
@@ -257,6 +260,7 @@
if label_args is None:
label_args = {}
self.label_args = label_args
+ self.data_source = data_source
def __call__(self, plot):
x0, x1 = plot.xlim
@@ -277,26 +281,27 @@
# We want xi, yi in plot coordinates
xi, yi = np.mgrid[xx0:xx1:numPoints_x/(self.factor*1j),
yy0:yy1:numPoints_y/(self.factor*1j)]
+ data = self.data_source or plot.data
if plot._type_name in ['CuttingPlane','Projection','Slice']:
if plot._type_name == 'CuttingPlane':
- x = plot.data["px"]*dx
- y = plot.data["py"]*dy
- z = plot.data[self.field]
+ x = data["px"]*dx
+ y = data["py"]*dy
+ z = data[self.field]
elif plot._type_name in ['Projection','Slice']:
#Makes a copy of the position fields "px" and "py" and adds the
#appropriate shift to the copied field.
- AllX = np.zeros(plot.data["px"].size, dtype='bool')
- AllY = np.zeros(plot.data["py"].size, dtype='bool')
- XShifted = plot.data["px"].copy()
- YShifted = plot.data["py"].copy()
+ AllX = np.zeros(data["px"].size, dtype='bool')
+ AllY = np.zeros(data["py"].size, dtype='bool')
+ XShifted = data["px"].copy()
+ YShifted = data["py"].copy()
dom_x, dom_y = plot._period
for shift in np.mgrid[-1:1:3j]:
- xlim = ((plot.data["px"] + shift*dom_x >= x0) &
- (plot.data["px"] + shift*dom_x <= x1))
- ylim = ((plot.data["py"] + shift*dom_y >= y0) &
- (plot.data["py"] + shift*dom_y <= y1))
+ xlim = ((data["px"] + shift*dom_x >= x0) &
+ (data["px"] + shift*dom_x <= x1))
+ ylim = ((data["py"] + shift*dom_y >= y0) &
+ (data["py"] + shift*dom_y <= y1))
XShifted[xlim] += shift * dom_x
YShifted[ylim] += shift * dom_y
AllX |= xlim
@@ -309,7 +314,7 @@
# This converts XShifted and YShifted into plot coordinates
x = (XShifted[wI]-x0)*dx + xx0
y = (YShifted[wI]-y0)*dy + yy0
- z = plot.data[self.field][wI]
+ z = data[self.field][wI]
# Both the input and output from the triangulator are in plot
# coordinates
https://bitbucket.org/yt_analysis/yt/commits/a00e9c0b72fe/
Changeset: a00e9c0b72fe
Branch: yt
User: MatthewTurk
Date: 2013-09-10 20:04:51
Summary: Fixing wording.
Affected #: 1 file
diff -r 0b52b74efc3c0c8b4da64b86654ac9c669680635 -r a00e9c0b72fe33a82b264a1d4f74afffad11533a yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -239,8 +239,8 @@
contours generated, *factor* governs the number of points used in the
interpolation, *take_log* governs how it is contoured and *clim* gives
the (upper, lower) limits for contouring. An alternate data source can be
- specified with *data_source*, but by default the plot being annotated will
- be queried.
+ specified with *data_source*, but by default the plot's data source will be
+ queried.
"""
_type_name = "contour"
def __init__(self, field, ncont=5, factor=4, clim=None,
https://bitbucket.org/yt_analysis/yt/commits/c65d8184a73c/
Changeset: c65d8184a73c
Branch: yt
User: MatthewTurk
Date: 2013-09-12 21:52:05
Summary: Somehow a few of these changes were stripped.
Affected #: 2 files
diff -r 7a7ca4d5a1b3747a06ea76b8d090e33413717b06 -r c65d8184a73c0e457459b703f713392e5d79e426 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -214,17 +214,20 @@
class ContourCallback(PlotCallback):
"""
annotate_contour(field, ncont=5, factor=4, take_log=None, clim=None,
- plot_args=None, label=False, label_args=None):
+ plot_args=None, label=False, label_args=None,
+ data_source=None):
Add contours in *field* to the plot. *ncont* governs the number of
contours generated, *factor* governs the number of points used in the
interpolation, *take_log* governs how it is contoured and *clim* gives
- the (upper, lower) limits for contouring.
+ the (upper, lower) limits for contouring. An alternate data source can be
+ specified with *data_source*, but by default the plot's data source will be
+ queried.
"""
_type_name = "contour"
def __init__(self, field, ncont=5, factor=4, clim=None,
plot_args = None, label = False, take_log = None,
- label_args = None):
+ label_args = None, data_source = None):
PlotCallback.__init__(self)
self.ncont = ncont
self.field = field
@@ -239,6 +242,7 @@
if label_args is None:
label_args = {}
self.label_args = label_args
+ self.data_source = data_source
def __call__(self, plot):
x0, x1 = plot.xlim
@@ -259,26 +263,27 @@
# We want xi, yi in plot coordinates
xi, yi = np.mgrid[xx0:xx1:numPoints_x/(self.factor*1j),
yy0:yy1:numPoints_y/(self.factor*1j)]
+ data = self.data_source or plot.data
if plot._type_name in ['CuttingPlane','Projection','Slice']:
if plot._type_name == 'CuttingPlane':
- x = plot.data["px"]*dx
- y = plot.data["py"]*dy
- z = plot.data[self.field]
+ x = data["px"]*dx
+ y = data["py"]*dy
+ z = data[self.field]
elif plot._type_name in ['Projection','Slice']:
#Makes a copy of the position fields "px" and "py" and adds the
#appropriate shift to the copied field.
- AllX = np.zeros(plot.data["px"].size, dtype='bool')
- AllY = np.zeros(plot.data["py"].size, dtype='bool')
- XShifted = plot.data["px"].copy()
- YShifted = plot.data["py"].copy()
+ AllX = np.zeros(data["px"].size, dtype='bool')
+ AllY = np.zeros(data["py"].size, dtype='bool')
+ XShifted = data["px"].copy()
+ YShifted = data["py"].copy()
dom_x, dom_y = plot._period
for shift in np.mgrid[-1:1:3j]:
- xlim = ((plot.data["px"] + shift*dom_x >= x0) &
- (plot.data["px"] + shift*dom_x <= x1))
- ylim = ((plot.data["py"] + shift*dom_y >= y0) &
- (plot.data["py"] + shift*dom_y <= y1))
+ xlim = ((data["px"] + shift*dom_x >= x0) &
+ (data["px"] + shift*dom_x <= x1))
+ ylim = ((data["py"] + shift*dom_y >= y0) &
+ (data["py"] + shift*dom_y <= y1))
XShifted[xlim] += shift * dom_x
YShifted[ylim] += shift * dom_y
AllX |= xlim
@@ -291,7 +296,7 @@
# This converts XShifted and YShifted into plot coordinates
x = (XShifted[wI]-x0)*dx + xx0
y = (YShifted[wI]-y0)*dy + yy0
- z = plot.data[self.field][wI]
+ z = data[self.field][wI]
# Both the input and output from the triangulator are in plot
# coordinates
diff -r 7a7ca4d5a1b3747a06ea76b8d090e33413717b06 -r c65d8184a73c0e457459b703f713392e5d79e426 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -1072,14 +1072,16 @@
type = self._plot_type
if type in ['Projection','OffAxisProjection']:
weight = self.data_source.weight_field
+ if weight is not None:
+ weight = weight.replace(' ', '_')
if 'Cutting' in self.data_source.__class__.__name__:
type = 'OffAxisSlice'
for k, v in self.plots.iteritems():
if axis:
- n = "%s_%s_%s_%s" % (name, type, axis, k)
+ n = "%s_%s_%s_%s" % (name, type, axis, k.replace(' ', '_'))
else:
# for cutting planes
- n = "%s_%s_%s" % (name, type, k)
+ n = "%s_%s_%s" % (name, type, k.replace(' ', '_'))
if weight:
n += "_%s" % (weight)
names.append(v.save(n,mpl_kwargs))
@@ -1777,7 +1779,16 @@
def __init__(
self, data, cbname, cmap, extent, aspect, zlim, size, fontsize,
figure, axes, cax):
- fsize, axrect, caxrect = self._get_best_layout(size, fontsize)
+ self._draw_colorbar = True
+ self._draw_axes = True
+ self._cache_layout(size, fontsize)
+
+ # Make room for a colorbar
+ self.input_size = size
+ self.fsize = [size[0] + self._cbar_inches[self._draw_colorbar], size[1]]
+
+ # Compute layout
+ axrect, caxrect = self._get_best_layout(fontsize)
if np.any(np.array(axrect) < 0):
mylog.warning('The axis ratio of the requested plot is very narrow. '
'There is a good chance the plot will not look very good, '
@@ -1786,7 +1797,7 @@
axrect = (0.07, 0.10, 0.80, 0.80)
caxrect = (0.87, 0.10, 0.04, 0.80)
ImagePlotMPL.__init__(
- self, fsize, axrect, caxrect, zlim, figure, axes, cax)
+ self, self.fsize, axrect, caxrect, zlim, figure, axes, cax)
self._init_image(data, cbname, cmap, extent, aspect)
self.image.axes.ticklabel_format(scilimits=(-2,3))
if cbname == 'linear':
@@ -1794,31 +1805,74 @@
self.cb.formatter.set_powerlimits((-2,3))
self.cb.update_ticks()
- def _get_best_layout(self, size, fontsize=18):
- aspect = 1.0*size[0]/size[1]
- fontscale = fontsize / 18.0
+ def _toggle_axes(self, choice):
+ self._draw_axes = choice
+ self.axes.get_xaxis().set_visible(choice)
+ self.axes.get_yaxis().set_visible(choice)
+ axrect, caxrect = self._get_best_layout()
+ self.axes.set_position(axrect)
+ self.cax.set_position(caxrect)
- # add room for a colorbar
- cbar_inches = fontscale*0.7
- newsize = [size[0] + cbar_inches, size[1]]
+ def _toggle_colorbar(self, choice):
+ self._draw_colorbar = choice
+ self.cax.set_visible(choice)
+ self.fsize = [self.input_size[0] + self._cbar_inches[choice], self.input_size[1]]
+ axrect, caxrect = self._get_best_layout()
+ self.axes.set_position(axrect)
+ self.cax.set_position(caxrect)
+
+ def hide_axes(self):
+ self._toggle_axes(False)
+ return self
+
+ def show_axes(self):
+ self._toggle_axes(True)
+ return self
+
+ def hide_colorbar(self):
+ self._toggle_colorbar(False)
+ return self
+
+ def show_colorbar(self):
+ self._toggle_colorbar(True)
+ return self
+
+ def _cache_layout(self, size, fontsize):
+ self._cbar_inches = {}
+ self._text_buffx = {}
+ self._text_bottomy = {}
+ self._text_topy = {}
+
+ self._aspect = 1.0*size[0]/size[1]
+ self._fontscale = fontsize / 18.0
+
+ # Leave room for a colorbar, if we are drawing it.
+ self._cbar_inches[True] = self._fontscale*0.7
+ self._cbar_inches[False] = 0
# add buffers for text, and a bit of whitespace on top
- text_buffx = fontscale * 1.0/(newsize[0])
- text_bottomy = fontscale * 0.7/size[1]
- text_topy = fontscale * 0.3/size[1]
+ self._text_buffx[True] = self._fontscale * 1.0/(size[0] + self._cbar_inches[True])
+ self._text_bottomy[True] = self._fontscale * 0.7/size[1]
+ self._text_topy[True] = self._fontscale * 0.3/size[1]
+ # No buffer for text if we're not drawing axes
+ self._text_buffx[False] = 0
+ self._text_bottomy[False] = 0
+ self._text_topy[False] = 0
+
+ def _get_best_layout(self, fontsize=18):
# calculate how much room the colorbar takes
- cbar_frac = cbar_inches/newsize[0]
+ cbar_frac = self._cbar_inches[self._draw_colorbar]/self.fsize[0]
# Calculate y fraction, then use to make x fraction.
- yfrac = 1.0-text_bottomy-text_topy
- ysize = yfrac*size[1]
- xsize = aspect*ysize
- xfrac = xsize/newsize[0]
+ yfrac = 1.0-self._text_bottomy[self._draw_axes]-self._text_topy[self._draw_axes]
+ ysize = yfrac*self.fsize[1]
+ xsize = self._aspect*ysize
+ xfrac = xsize/self.fsize[0]
# Now make sure it all fits!
- xbig = xfrac + text_buffx + 2.0*cbar_frac
- ybig = yfrac + text_bottomy + text_topy
+ xbig = xfrac + self._text_buffx[self._draw_axes] + 2.0*cbar_frac
+ ybig = yfrac + self._text_bottomy[self._draw_axes] + self._text_topy[self._draw_axes]
if xbig > 1:
xsize /= xbig
@@ -1826,9 +1880,20 @@
if ybig > 1:
xsize /= ybig
ysize /= ybig
- xfrac = xsize/newsize[0]
- yfrac = ysize/newsize[1]
+ xfrac = xsize/self.fsize[0]
+ yfrac = ysize/self.fsize[1]
- axrect = (text_buffx, text_bottomy, xfrac, yfrac )
- caxrect = (text_buffx+xfrac, text_bottomy, cbar_frac/4., yfrac )
- return newsize, axrect, caxrect
+ axrect = (
+ self._text_buffx[self._draw_axes],
+ self._text_bottomy[self._draw_axes],
+ xfrac,
+ yfrac
+ )
+
+ caxrect = (
+ self._text_buffx[self._draw_axes]+xfrac,
+ self._text_bottomy[self._draw_axes],
+ cbar_frac/4.,
+ yfrac
+ )
+ return axrect, caxrect
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