# HG changeset patch # User Britton Smith # Date 1247506261 14400 # Branch trunk # Node ID d34667423b3940c6105dbb70018eba21a0c66524 # Parent f938afbd0ef3d4d3ae3f6d82f1039b9d84f2ddf0 [svn r1371] Adding new RavenPlot.set_zlim keyword options. Documentation to follow. diff -r f938afbd0ef3d4d3ae3f6d82f1039b9d84f2ddf0 -r d34667423b3940c6105dbb70018eba21a0c66524 yt/raven/PlotCollection.py --- a/yt/raven/PlotCollection.py Wed Jul 08 19:30:40 2009 -0700 +++ b/yt/raven/PlotCollection.py Mon Jul 13 13:31:01 2009 -0400 @@ -102,16 +102,23 @@ for plot in self.plots: plot.set_ylim(ymin, ymax) - def set_zlim(self, zmin, zmax,dex=None): + def set_zlim(self, zmin, zmax, **kwargs): """ Set the limits of the colorbar. 'min' or 'max' are possible inputs when combined with dex=value, where value gives the maximum number of dex to go above/below the min/max. If value is larger than the true range of values, min/max are limited to true range. + + Only ONE of the following options can be specified. If all 3 are + specified, they will be used in the following precedence order: + ticks - a list of floating point numbers at which to put ticks + minmaxtick - display DEFAULT ticks with min & max also displayed + nticks - if ticks not specified, can automatically determine a + number of ticks to be evenly spaced in log space """ for plot in self.plots: plot.set_autoscale(False) - plot.set_zlim(zmin, zmax, dex=dex) + plot.set_zlim(zmin, zmax, **kwargs) def set_lim(self, lim): """ diff -r f938afbd0ef3d4d3ae3f6d82f1039b9d84f2ddf0 -r d34667423b3940c6105dbb70018eba21a0c66524 yt/raven/PlotTypes.py --- a/yt/raven/PlotTypes.py Wed Jul 08 19:30:40 2009 -0700 +++ b/yt/raven/PlotTypes.py Mon Jul 13 13:31:01 2009 -0400 @@ -141,21 +141,47 @@ """ self._axes.set_ylim(ymin, ymax) - def set_zlim(self, zmin, zmax, dex=None): + def set_zlim(self, zmin, zmax, dex=None, nticks=None, ticks=None, minmaxtick=False): """ Set the z boundaries of this plot. + + Only ONE of the following options can be specified. If all 3 are + specified, they will be used in the following precedence order: + ticks - a list of floating point numbers at which to put ticks + minmaxtick - display DEFAULT ticks with min & max also displayed + nticks - if ticks not specified, can automatically determine a + number of ticks to be evenly spaced in log space """ # This next call fixes some things, but is slower... #self._redraw_image() - if (zmin is None) or (zmax is None): + if (zmin in (None,'min')) or (zmax in (None,'max')): + imbuff = self._axes.images[-1]._A if zmin == 'min': - zmin = na.nanmin(self._axes.images[-1]._A) + zmin = na.nanmin(imbuff[na.nonzero(imbuff)]) if dex is not None: - zmax = min(zmin*10**(dex),na.nanmax(self._axes.images[-1]._A)) + zmax = min(zmin*10**(dex),na.nanmax(imbuff)) if zmax == 'max': - zmax = na.nanmax(self._axes.images[-1]._A) + zmax = na.nanmax(imbuff) if dex is not None: - zmin = max(zmax/(10**(dex)),na.nanmin(self._axes.images[-1]._A)) + zmin = max(zmax/(10**(dex)),na.nanmin(imbuff)) + if ticks is not None: + ticks = na.sort(ticks) + self.colorbar.locator = matplotlib.ticker.FixedLocator(ticks) + self.colorbar.formatter = matplotlib.ticker.FixedFormatter(["%0.2e" % (x) for x in ticks]) + elif minmaxtick: + ticks = na.array(self.colorbar._ticker()[1],dtype='float') + ticks = [zmin] + ticks.tolist() + [zmax] + self.colorbar.locator = matplotlib.ticker.FixedLocator(ticks) + self.colorbar.formatter = matplotlib.ticker.FixedFormatter(["%0.2e" % (x) for x in ticks]) + elif nticks is not None: + lin = na.linspace(na.log10(zmin),na.log10(zmax),nticks) + self.colorbar.locator = matplotlib.ticker.FixedLocator(10**lin) + self.colorbar.formatter = matplotlib.ticker.FixedFormatter(["%0.2e" % (10**x) for x in lin]) + else: + if hasattr(self,'_old_locator'): + self.colorbar.locator = self._old_locator + if hasattr(self,'_old_formatter'): + self.colorbar.formatter = self._old_formatter self.norm.autoscale(na.array([zmin,zmax])) self.image.changed() if self.colorbar is not None: @@ -276,6 +302,8 @@ self.colorbar = self._figure.colorbar(self._axes.images[-1], \ extend='neither', \ shrink=0.95) + self._old_locator = self.colorbar.locator + self._old_formatter = self.colorbar.formatter else: self.colorbar = None self.set_width(1,'unitary')