Skip to content

Commit

Permalink
Merge pull request matplotlib#2182 from NelleV/axes_module_plotting
Browse files Browse the repository at this point in the history
[Sprint] ENH Move _string_to_bool from axes._base to cbook
  • Loading branch information
dmcdougall committed Jun 30, 2013
2 parents 4b588a7 + d32e2ab commit e7f6874
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
1 change: 0 additions & 1 deletion lib/matplotlib/axes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from matplotlib.axes._subplots import *
from matplotlib.axes._axes import *
from matplotlib.axes._base import _string_to_bool
1 change: 1 addition & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
rcParams = matplotlib.rcParams

import matplotlib.cbook as cbook
from matplotlib.cbook import _string_to_bool
import matplotlib.collections as mcoll
import matplotlib.colors as mcolors
import matplotlib.contour as mcontour
Expand Down
11 changes: 1 addition & 10 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
rcParams = matplotlib.rcParams

from matplotlib import cbook
from matplotlib.cbook import _string_to_bool
from matplotlib import docstring
import matplotlib.colors as mcolors
import matplotlib.lines as mlines
Expand All @@ -33,16 +34,6 @@
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 style color/line style format string. Return a
Expand Down
28 changes: 20 additions & 8 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class MatplotlibDeprecationWarning(UserWarning):
mplDeprecation = MatplotlibDeprecationWarning


def _generate_deprecation_message(
since, message='', name='', alternative='', pending=False,
obj_type='attribute'):
def _generate_deprecation_message(since, message='', name='',
alternative='', pending=False,
obj_type='attribute'):

if not message:
altmessage = ''
Expand Down Expand Up @@ -464,9 +464,11 @@ class CallbackRegistry:
"""
def __init__(self, *args):
if len(args):
warn_deprecated('1.3', message=
"CallbackRegistry no longer requires a list of callback "
"types. Ignoring arguments. *args will be removed in 1.5")
warn_deprecated(
'1.3',
message="CallbackRegistry no longer requires a list of "
"callback types. Ignoring arguments. *args will "
"be removed in 1.5")
self.callbacks = dict()
self._cid = 0
self._func_cid_map = {}
Expand Down Expand Up @@ -750,6 +752,16 @@ def is_scalar_or_string(val):
return is_string_like(val) or not iterable(val)


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 get_sample_data(fname, asfileobj=True):
"""
Return a sample data file. *fname* is a path relative to the
Expand Down Expand Up @@ -1724,8 +1736,8 @@ def simple_linear_interpolation(a, steps):

def recursive_remove(path):
if os.path.isdir(path):
for fname in glob.glob(os.path.join(path, '*')) + \
glob.glob(os.path.join(path, '.*')):
for fname in (glob.glob(os.path.join(path, '*')) +
glob.glob(os.path.join(path, '.*'))):
if os.path.isdir(fname):
recursive_remove(fname)
os.removedirs(fname)
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import matplotlib.colorbar
from matplotlib import _pylab_helpers, interactive
from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike
from matplotlib.cbook import _string_to_bool
from matplotlib import docstring
from matplotlib.backend_bases import FigureCanvasBase
from matplotlib.figure import Figure, figaspect
Expand All @@ -35,7 +36,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, _string_to_bool
from matplotlib.axes import Axes, Subplot
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
Expand Down
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ def grid(self, b=True, **kwargs):
# TODO: Operate on each axes separately
if len(kwargs) :
b = True
self._draw_grid = maxes._string_to_bool(b)
self._draw_grid = cbook._string_to_bool(b)

def ticklabel_format(self, **kwargs) :
"""
Expand Down

0 comments on commit e7f6874

Please sign in to comment.