Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9958f4e

Browse files
committed
ENH matplotlib toolkits now uses the new utils module instead of the deprecated cbook module
1 parent 91e2e82 commit 9958f4e

File tree

12 files changed

+45
-46
lines changed

12 files changed

+45
-46
lines changed

lib/matplotlib/units.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def default_units(x, axis):
4343
4444
"""
4545
from __future__ import print_function
46-
from matplotlib._cbook import iterable, is_numlike
46+
from matplotlib.utils import iterable, is_numlike
4747

4848

4949
class AxisInfo:

lib/mpl_toolkits/axes_grid/colorbar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import matplotlib.cm as cm
2626
from matplotlib import docstring
2727
import matplotlib.ticker as ticker
28-
import matplotlib.cbook as cbook
28+
import matplotlib.utils as utils
2929
import matplotlib.collections as collections
3030
import matplotlib.contour as contour
3131
from matplotlib.path import Path
@@ -376,7 +376,7 @@ def __init__(self, ax, cmap=None,
376376
formatter = ticker.LogFormatter()
377377
else:
378378
formatter = None
379-
elif cbook.is_string_like(format):
379+
elif utils.is_string_like(format):
380380
formatter = ticker.FormatStrFormatter(format)
381381
else:
382382
formatter = format # Assume it is a Formatter
@@ -386,7 +386,7 @@ def __init__(self, ax, cmap=None,
386386
else:
387387
self.cbar_axis.set_major_formatter(formatter)
388388

389-
if cbook.iterable(ticks):
389+
if utils.iterable(ticks):
390390
self.cbar_axis.set_ticks(ticks)
391391
elif ticks is not None:
392392
self.cbar_axis.set_major_locator(ticks)

lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import matplotlib.cbook as cbook
1+
import matplotlib.utils as utils
22

33
import matplotlib.pyplot as plt
44
import matplotlib.axes as maxes
@@ -240,7 +240,7 @@ def __init__(self, fig,
240240

241241
h = []
242242
v = []
243-
if cbook.is_string_like(rect) or cbook.is_numlike(rect):
243+
if utils.is_string_like(rect) or utils.is_numlike(rect):
244244
self._divider = SubplotDivider(fig, rect, horizontal=h, vertical=v,
245245
aspect=False)
246246
elif isinstance(rect, SubplotSpec):
@@ -554,7 +554,7 @@ def __init__(self, fig,
554554

555555
h = []
556556
v = []
557-
if cbook.is_string_like(rect) or cbook.is_numlike(rect):
557+
if utils.is_string_like(rect) or utils.is_numlike(rect):
558558
self._divider = SubplotDivider(fig, rect, horizontal=h, vertical=v,
559559
aspect=aspect)
560560
elif isinstance(rect, SubplotSpec):

lib/mpl_toolkits/axes_grid1/axes_size.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class (or others) to determine the size of each axes. The unit
1111
1212
"""
1313

14-
import matplotlib.cbook as cbook
14+
import matplotlib.utils as utils
1515
from matplotlib.axes import Axes
1616

1717
class _Base(object):
@@ -230,9 +230,9 @@ def from_any(size, fraction_ref=None):
230230
>>> Size.from_any("50%", a) # => Size.Fraction(0.5, a)
231231
232232
"""
233-
if cbook.is_numlike(size):
233+
if utils.is_numlike(size):
234234
return Fixed(size)
235-
elif cbook.is_string_like(size):
235+
elif utils.is_string_like(size):
236236
if size[-1] == "%":
237237
return Fraction(float(size[:-1])/100., fraction_ref)
238238

lib/mpl_toolkits/axes_grid1/colorbar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import matplotlib.cm as cm
2626
from matplotlib import docstring
2727
import matplotlib.ticker as ticker
28-
import matplotlib.cbook as cbook
28+
import matplotlib.utils as utils
2929
import matplotlib.collections as collections
3030
import matplotlib.contour as contour
3131
from matplotlib.path import Path
@@ -376,7 +376,7 @@ def __init__(self, ax, cmap=None,
376376
formatter = ticker.LogFormatter()
377377
else:
378378
formatter = None
379-
elif cbook.is_string_like(format):
379+
elif utils.is_string_like(format):
380380
formatter = ticker.FormatStrFormatter(format)
381381
else:
382382
formatter = format # Assume it is a Formatter
@@ -386,7 +386,7 @@ def __init__(self, ax, cmap=None,
386386
else:
387387
self.cbar_axis.set_major_formatter(formatter)
388388

389-
if cbook.iterable(ticks):
389+
if utils.iterable(ticks):
390390
self.cbar_axis.set_ticks(ticks)
391391
elif ticks is not None:
392392
self.cbar_axis.set_major_locator(ticks)

lib/mpl_toolkits/axes_grid1/parasite_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import numpy as np
1616

17-
import matplotlib.cbook as cbook
18-
is_string_like = cbook.is_string_like
17+
import matplotlib.utils as utils
18+
is_string_like = utils.is_string_like
1919

2020

2121
class ParasiteAxesBase:

lib/mpl_toolkits/axisartist/grid_finder.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import print_function
22

33
import numpy as np
4-
import matplotlib.cbook as mcbook
54
from matplotlib.transforms import Bbox
65
import clip_path
76
clip_line_to_rect = clip_path.clip_line_to_rect

lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ def curvelinear_test2(fig):
580580

581581
from mpl_toolkits.axes_grid.parasite_axes import SubplotHost, \
582582
ParasiteAxesAuxTrans
583-
import matplotlib.cbook as cbook
583+
import matplotlib.utils as utils
584584

585585
# PolarAxes.PolarTransform takes radian. However, we want our coordinate
586586
# system in degree
@@ -649,7 +649,7 @@ def curvelinear_test2(fig):
649649
# note that ax2.transData == tr + ax1.transData
650650
# Anthing you draw in ax2 will match the ticks and grids of ax1.
651651
ax1.parasites.append(ax2)
652-
intp = cbook.simple_linear_interpolation
652+
intp = utils.simple_linear_interpolation
653653
ax2.plot(intp(np.array([0, 30]), 50),
654654
intp(np.array([10., 10.]), 50))
655655

@@ -747,7 +747,7 @@ def curvelinear_test3(fig):
747747
# # note that ax2.transData == tr + ax1.transData
748748
# # Anthing you draw in ax2 will match the ticks and grids of ax1.
749749
# ax1.parasites.append(ax2)
750-
# intp = cbook.simple_linear_interpolation
750+
# intp = utils.simple_linear_interpolation
751751
# ax2.plot(intp(np.array([0, 30]), 50),
752752
# intp(np.array([10., 10.]), 50))
753753

lib/mpl_toolkits/exceltools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import xlwt as excel
2626

27-
import matplotlib.cbook as cbook
27+
import matplotlib.utils as utils
2828
import matplotlib.mlab as mlab
2929

3030

@@ -83,7 +83,7 @@ def rec2excel(r, ws, formatd=None, rownum=0, colnum=0, nanstr='NaN', infstr='Inf
8383
"""
8484

8585
autosave = False
86-
if cbook.is_string_like(ws):
86+
if utils.is_string_like(ws):
8787
filename = ws
8888
wb = excel.Workbook()
8989
ws = wb.add_sheet('worksheet')

lib/mpl_toolkits/gtktools.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import copy
3535
import gtk, gobject
3636
import numpy as npy
37-
import matplotlib.cbook as cbook
37+
import matplotlib.utils as utils
3838
import matplotlib.mlab as mlab
3939

4040

@@ -356,7 +356,7 @@ class RecListStore(gtk.ListStore):
356356
357357
* stringd - a dict mapping dtype names to a list of valid strings for the combo drop downs
358358
359-
* callbacks - a matplotlib.cbook.CallbackRegistry. Connect to the cell_changed with
359+
* callbacks - a matplotlib.utils.CallbackRegistry. Connect to the cell_changed with
360360
361361
def mycallback(liststore, rownum, colname, oldval, newval):
362362
print 'verify: old=%s, new=%s, rec=%s'%(oldval, newval, liststore.r[rownum][colname])
@@ -381,7 +381,7 @@ def __init__(self, r, formatd=None, stringd=None):
381381
formatd = mlab.get_formatd(r)
382382

383383
self.stringd = stringd
384-
self.callbacks = cbook.CallbackRegistry(['cell_changed'])
384+
self.callbacks = utils.CallbackRegistry(['cell_changed'])
385385

386386
self.r = r
387387

@@ -439,7 +439,7 @@ def position_edited(self, renderer, path, newtext, position):
439439
oldval = self.r[rownum][colname]
440440
try: newval = format.fromstr(newtext)
441441
except ValueError:
442-
msg = cbook.exception_to_str('Error converting "%s"'%newtext)
442+
msg = utils.exception_to_str('Error converting "%s"'%newtext)
443443
error_message(msg, title='Error')
444444
return
445445
self.r[rownum][colname] = newval

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from matplotlib.cm import ScalarMappable
1515
from matplotlib.patches import Patch
1616
from matplotlib.colors import Normalize
17-
from matplotlib.cbook import iterable
17+
from matplotlib.utils import iterable
1818

1919
import warnings
2020
import numpy as np

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import matplotlib.axes as maxes
1717
from matplotlib.axes import Axes, rcParams
18-
from matplotlib import cbook
18+
import matplotlib.utils as utils
1919
import matplotlib.transforms as mtransforms
2020
from matplotlib.transforms import Bbox
2121
import matplotlib.collections as mcoll
@@ -38,7 +38,7 @@ class Axes3D(Axes):
3838
3D axes object.
3939
"""
4040
name = '3d'
41-
_shared_z_axes = cbook.Grouper()
41+
_shared_z_axes = utils.Grouper()
4242

4343
def __init__(self, fig, rect=None, *args, **kwargs):
4444
'''
@@ -547,7 +547,7 @@ def get_w_lims(self):
547547
return minx, maxx, miny, maxy, minz, maxz
548548

549549
def _determine_lims(self, xmin=None, xmax=None, *args, **kwargs):
550-
if xmax is None and cbook.iterable(xmin):
550+
if xmax is None and utils.iterable(xmin):
551551
xmin, xmax = xmin
552552
if xmin == xmax:
553553
xmin -= 0.05
@@ -827,7 +827,7 @@ def get_zmajorticklabels(self) :
827827
828828
.. versionadded :: 1.1.0
829829
"""
830-
return cbook.silent_list('Text zticklabel',
830+
return utils.silent_list('Text zticklabel',
831831
self.zaxis.get_majorticklabels())
832832

833833
def get_zminorticklabels(self) :
@@ -840,7 +840,7 @@ def get_zminorticklabels(self) :
840840
841841
.. versionadded :: 1.1.0
842842
"""
843-
return cbook.silent_list('Text zticklabel',
843+
return utils.silent_list('Text zticklabel',
844844
self.zaxis.get_minorticklabels())
845845

846846
def set_zticklabels(self, *args, **kwargs) :
@@ -865,7 +865,7 @@ def get_zticklabels(self, minor=False) :
865865
866866
.. versionadded:: 1.1.0
867867
"""
868-
return cbook.silent_list('Text zticklabel',
868+
return utils.silent_list('Text zticklabel',
869869
self.zaxis.get_ticklabels(minor=minor))
870870

871871
def zaxis_date(self, tz=None) :
@@ -1491,23 +1491,23 @@ def plot(self, xs, ys, *args, **kwargs):
14911491

14921492
argsi = 0
14931493
# First argument is array of zs
1494-
if len(args) > 0 and cbook.iterable(args[0]) and \
1494+
if len(args) > 0 and utils.iterable(args[0]) and \
14951495
len(xs) == len(args[0]) :
14961496
# So, we know that it is an array with
14971497
# first dimension the same as xs.
14981498
# Next, check to see if the data contained
14991499
# therein (if any) is scalar (and not another array).
1500-
if len(args[0]) == 0 or cbook.is_scalar(args[0][0]) :
1500+
if len(args[0]) == 0 or utils.is_scalar(args[0][0]) :
15011501
zs = args[argsi]
15021502
argsi += 1
15031503

15041504
# First argument is z value
1505-
elif len(args) > 0 and cbook.is_scalar(args[0]):
1505+
elif len(args) > 0 and utils.is_scalar(args[0]):
15061506
zs = args[argsi]
15071507
argsi += 1
15081508

15091509
# Match length
1510-
if not cbook.iterable(zs):
1510+
if not utils.iterable(zs):
15111511
zs = np.ones(len(xs)) * zs
15121512

15131513
lines = Axes.plot(self, xs, ys, *args[argsi:], **kwargs)
@@ -2169,16 +2169,16 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c='b', *args, **kwargs):
21692169

21702170
s = np.ma.ravel(s) # This doesn't have to match x, y in size.
21712171

2172-
cstr = cbook.is_string_like(c) or cbook.is_sequence_of_strings(c)
2172+
cstr = utils.is_string_like(c) or utils.is_sequence_of_strings(c)
21732173
if not cstr:
21742174
c = np.asanyarray(c)
21752175
if c.size == xs.size:
21762176
c = np.ma.ravel(c)
21772177

2178-
xs, ys, zs, s, c = cbook.delete_masked_points(xs, ys, zs, s, c)
2178+
xs, ys, zs, s, c = utils.delete_masked_points(xs, ys, zs, s, c)
21792179

21802180
patches = Axes.scatter(self, xs, ys, s=s, c=c, *args, **kwargs)
2181-
if not cbook.iterable(zs):
2181+
if not utils.iterable(zs):
21822182
is_2d = True
21832183
zs = np.ones(len(xs)) * zs
21842184
else:
@@ -2220,7 +2220,7 @@ def bar(self, left, height, zs=0, zdir='z', *args, **kwargs):
22202220

22212221
patches = Axes.bar(self, left, height, *args, **kwargs)
22222222

2223-
if not cbook.iterable(zs):
2223+
if not utils.iterable(zs):
22242224
zs = np.ones(len(left)) * zs
22252225

22262226
verts = []
@@ -2282,18 +2282,18 @@ def bar3d(self, x, y, z, dx, dy, dz, color='b',
22822282
'''
22832283
had_data = self.has_data()
22842284

2285-
if not cbook.iterable(x):
2285+
if not utils.iterable(x):
22862286
x = [x]
2287-
if not cbook.iterable(y):
2287+
if not utils.iterable(y):
22882288
y = [y]
2289-
if not cbook.iterable(z):
2289+
if not utils.iterable(z):
22902290
z = [z]
22912291

2292-
if not cbook.iterable(dx):
2292+
if not utils.iterable(dx):
22932293
dx = [dx]
2294-
if not cbook.iterable(dy):
2294+
if not utils.iterable(dy):
22952295
dy = [dy]
2296-
if not cbook.iterable(dz):
2296+
if not utils.iterable(dz):
22972297
dz = [dz]
22982298

22992299
if len(dx) == 1:

0 commit comments

Comments
 (0)