From: <jr...@us...> - 2009-02-03 17:25:52
|
Revision: 6870 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6870&view=rev Author: jrevans Date: 2009-02-03 17:25:49 +0000 (Tue, 03 Feb 2009) Log Message: ----------- User specified tickers and labels for any given axis will now take precedence over "default" values. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/axis.py Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-02-03 13:59:00 UTC (rev 6869) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-02-03 17:25:49 UTC (rev 6870) @@ -2672,12 +2672,7 @@ :meth:`text` for information on how override and the optional args work """ - - label = self.xaxis.get_label() - label.set_text(xlabel) - if fontdict is not None: label.update(fontdict) - label.update(kwargs) - return label + return self.xaxis.set_label_text(xlabel, fontdict, **kwargs) set_xlabel.__doc__ = cbook.dedent(set_xlabel.__doc__) % martist.kwdocd def get_ylabel(self): @@ -2704,11 +2699,7 @@ :meth:`text` for information on how override and the optional args work """ - label = self.yaxis.get_label() - label.set_text(ylabel) - if fontdict is not None: label.update(fontdict) - label.update(kwargs) - return label + return self.yaxis.set_label_text(ylabel, fontdict, **kwargs) set_ylabel.__doc__ = cbook.dedent(set_ylabel.__doc__) % martist.kwdocd def text(self, x, y, s, fontdict=None, Modified: trunk/matplotlib/lib/matplotlib/axis.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axis.py 2009-02-03 13:59:00 UTC (rev 6869) +++ trunk/matplotlib/lib/matplotlib/axis.py 2009-02-03 17:25:49 UTC (rev 6870) @@ -514,6 +514,15 @@ artist.Artist.__init__(self) self.set_figure(axes.figure) + # Keep track of setting to the default value, this allows use to know + # if any of the following values is explicitly set by the user, so as + # to not overwrite their settings with any of our 'auto' settings. + self.isDefault_majloc = True + self.isDefault_minloc = True + self.isDefault_majfmt = True + self.isDefault_minfmt = True + self.isDefault_label = True + self.axes = axes self.major = Ticker() self.minor = Ticker() @@ -568,6 +577,11 @@ self._scale = mscale.scale_factory(value, self, **kwargs) self._scale.set_default_locators_and_formatters(self) + self.isDefault_majloc = True + self.isDefault_minloc = True + self.isDefault_majfmt = True + self.isDefault_minfmt = True + def limit_range_for_scale(self, vmin, vmax): return self._scale.limit_range_for_scale(vmin, vmax, self.get_minpos()) @@ -587,6 +601,18 @@ self.set_minor_locator(mticker.NullLocator()) self.set_minor_formatter(mticker.NullFormatter()) + self.set_label_text('') + self._set_artist_props(self.label) + + # Keep track of setting to the default value, this allows use to know + # if any of the following values is explicitly set by the user, so as + # to not overwrite their settings with any of our 'auto' settings. + self.isDefault_majloc = True + self.isDefault_minloc = True + self.isDefault_majfmt = True + self.isDefault_minfmt = True + self.isDefault_label = True + # Clear the callback registry for this axis, or it may "leak" self.callbacks = cbook.CallbackRegistry(('units', 'units finalize')) @@ -836,6 +862,10 @@ dest.label1On = src.label1On dest.label2On = src.label2On + def get_label_text(self): + 'Get the text of the label' + return self.label.get_text() + def get_major_locator(self): 'Get the locator of the major ticker' return self.major.locator @@ -958,17 +988,21 @@ info = self.converter.axisinfo(self.units, self) if info is None: return - if info.majloc is not None and self.major.locator!=info.majloc: + if info.majloc is not None and self.major.locator!=info.majloc and self.isDefault_majloc: self.set_major_locator(info.majloc) - if info.minloc is not None and self.minor.locator!=info.minloc: + self.isDefault_majloc = True + if info.minloc is not None and self.minor.locator!=info.minloc and self.isDefault_minloc: self.set_minor_locator(info.minloc) - if info.majfmt is not None and self.major.formatter!=info.majfmt: + self.isDefault_minloc = True + if info.majfmt is not None and self.major.formatter!=info.majfmt and self.isDefault_majfmt: self.set_major_formatter(info.majfmt) - if info.minfmt is not None and self.minor.formatter!=info.minfmt: + self.isDefault_majfmt = True + if info.minfmt is not None and self.minor.formatter!=info.minfmt and self.isDefault_minfmt: self.set_minor_formatter(info.minfmt) - if info.label is not None: - label = self.get_label() - label.set_text(info.label) + self.isDefault_minfmt = True + if info.label is not None and self.isDefault_label: + self.set_label_text(info.label) + self.isDefault_label = True def have_units(self): @@ -1010,12 +1044,24 @@ 'return the units for axis' return self.units + def set_label_text(self, label, fontdict = None, **kwargs): + """ Sets the text value of the axis label + + ACCEPTS: A string value for the label + """ + self.isDefault_label = False + self.label.set_text(label) + if fontdict is not None: self.label.update(fontdict) + self.label.update(kwargs) + return self.label + def set_major_formatter(self, formatter): """ Set the formatter of the major ticker ACCEPTS: A :class:`~matplotlib.ticker.Formatter` instance """ + self.isDefault_majfmt = False self.major.formatter = formatter formatter.set_axis(self) @@ -1026,6 +1072,7 @@ ACCEPTS: A :class:`~matplotlib.ticker.Formatter` instance """ + self.isDefault_minfmt = False self.minor.formatter = formatter formatter.set_axis(self) @@ -1036,6 +1083,7 @@ ACCEPTS: a :class:`~matplotlib.ticker.Locator` instance """ + self.isDefault_majloc = False self.major.locator = locator locator.set_axis(self) @@ -1046,6 +1094,7 @@ ACCEPTS: a :class:`~matplotlib.ticker.Locator` instance """ + self.isDefault_minloc = False self.minor.locator = locator locator.set_axis(self) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |