Revision: 8352 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8352&view=rev Author: efiring Date: 2010-05-31 19:41:20 +0000 (Mon, 31 May 2010)
Log Message: ----------- grid, box: allow 'on' or 'off' in place of boolean. Closes 2871949. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/pyplot.py Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2010-05-31 18:45:39 UTC (rev 8351) +++ trunk/matplotlib/lib/matplotlib/axes.py 2010-05-31 19:41:20 UTC (rev 8352) @@ -39,6 +39,15 @@ is_string_like = cbook.is_string_like is_sequence_of_strings = cbook.is_sequence_of_strings +def _string_to_bool(s): + if not is_string_like(s): + return s + if s == 'on': + return True + if s == 'off': + return False + raise ValueError("string argument must be either 'on' or 'off'") + def _process_plot_format(fmt): """ Process a matlab(TM) style color/line style format string. Return a @@ -1954,7 +1963,8 @@ grid(self, b=None, **kwargs) - Set the axes grids on or off; *b* is a boolean + Set the axes grids on or off; *b* is a boolean. (For Matlab + compatibility, *b* may also be a string, 'on' or 'off'.) If *b* is *None* and ``len(kwargs)==0``, toggle the grid state. If *kwargs* are supplied, it is assumed that you want a grid and *b* @@ -1968,7 +1978,9 @@ %(Line2D)s """ - if len(kwargs): b = True + if len(kwargs): + b = True + b = _string_to_bool(b) self.xaxis.grid(b, **kwargs) self.yaxis.grid(b, **kwargs) Modified: trunk/matplotlib/lib/matplotlib/pyplot.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pyplot.py 2010-05-31 18:45:39 UTC (rev 8351) +++ trunk/matplotlib/lib/matplotlib/pyplot.py 2010-05-31 19:41:20 UTC (rev 8352) @@ -12,7 +12,7 @@ from matplotlib.rcsetup import interactive_bk as _interactive_bk from matplotlib.artist import getp, get, Artist from matplotlib.artist import setp as _setp -from matplotlib.axes import Axes, Subplot +from matplotlib.axes import Axes, Subplot, _string_to_bool from matplotlib.projections import PolarAxes from matplotlib import mlab # for csv2rec, detrend_none, window_hanning from matplotlib.scale import get_scale_docs, get_scale_names @@ -886,10 +886,12 @@ def box(on=None): """ Turn the axes box on or off according to *on*. + *on* may be a boolean or a string, 'on' or 'off'. If *on* is *None*, toggle state. """ ax = gca() + on = _string_to_bool(on) if on is None: on = not ax.get_frame_on() ax.set_frame_on(on) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins