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

Skip to content

Commit 28af817

Browse files
committed
ENH updated the documentation to reflect the deprecation of the cbook method in favor of the utils module
1 parent 9d07dfc commit 28af817

File tree

11 files changed

+118
-117
lines changed

11 files changed

+118
-117
lines changed

doc/api/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
axes_api.rst
2222
axis_api.rst
2323
index_backend_api.rst
24-
cbook_api.rst
2524
cm_api.rst
2625
collections_api.rst
2726
colorbar_api.rst

doc/devel/coding_guide.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Style
4848
import numpy.ma as ma
4949
import matplotlib as mpl
5050
from matplotlib import pyplot as plt
51-
import matplotlib.cbook as cbook
51+
import matplotlib.utils as utils
5252
import matplotlib.collections as mcol
5353
import matplotlib.patches as mpatches
5454

@@ -257,8 +257,8 @@ distributed with matplotlib in the
257257
`lib/matplotlib/mpl-data/sample_data/` directory. Then in your
258258
example code you can load it into a file handle with::
259259

260-
import matplotlib.cbook as cbook
261-
fh = cbook.get_sample_data('mydata.dat')
260+
import matplotlib.utils as utils
261+
fh = utils.get_sample_data('mydata.dat')
262262

263263
.. _new-pyplot-function:
264264

doc/mpl_toolkits/axes_grid/figures/demo_colorbar_of_inset_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from mpl_toolkits.axes_grid.colorbar import colorbar
55

66
def get_demo_image():
7-
from matplotlib.cbook import get_sample_data
7+
from matplotlib.utils import get_sample_data
88
import numpy as np
99
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
1010
z = np.load(f)

doc/mpl_toolkits/axes_grid/figures/simple_rgb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
def get_demo_image():
66
import numpy as np
7-
from matplotlib.cbook import get_sample_data
7+
from matplotlib.utils import get_sample_data
88
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
99
z = np.load(f)
1010
# z is a numpy array of 15x15

doc/users/recipes.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ gracefully, and here are some tricks to help you work around them.
8787
We'll load up some sample date data which contains datetime.date
8888
objects in a numpy record array::
8989

90-
In [63]: datafile = cbook.get_sample_data('goog.npy')
90+
In [63]: datafile = utils.get_sample_data('goog.npy')
9191

9292
In [64]: r = np.load(datafile).view(np.recarray)
9393

@@ -116,8 +116,8 @@ you will see that the x tick labels are all squashed together.
116116
.. plot::
117117
:context:
118118

119-
import matplotlib.cbook as cbook
120-
datafile = cbook.get_sample_data('goog.npy')
119+
import matplotlib.utils as utils
120+
datafile = utils.get_sample_data('goog.npy')
121121
r = np.load(datafile).view(np.recarray)
122122
plt.figure()
123123
plt.plot(r.date, r.close)
@@ -175,10 +175,10 @@ right.
175175
import matplotlib.pyplot as plt
176176
import numpy as np
177177

178-
import matplotlib.cbook as cbook
178+
import matplotlib.utils as utils
179179

180180
# load up some sample financial data
181-
datafile = cbook.get_sample_data('goog.npy')
181+
datafile = utils.get_sample_data('goog.npy')
182182
r = np.load(datafile).view(np.recarray)
183183

184184
# create two subplots with the shared x and y axes

lib/matplotlib/utils/__init__.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,3 +1118,101 @@ def simple_linear_interpolation(a, steps):
11181118
result[steps::steps] = a1
11191119

11201120
return result
1121+
1122+
1123+
def report_memory(i=0): # argument may go away
1124+
'return the memory consumed by process'
1125+
from subprocess import Popen, PIPE
1126+
pid = os.getpid()
1127+
if sys.platform == 'sunos5':
1128+
a2 = Popen('ps -p %d -o osz' % pid, shell=True,
1129+
stdout=PIPE).stdout.readlines()
1130+
mem = int(a2[-1].strip())
1131+
elif sys.platform.startswith('linux'):
1132+
a2 = Popen('ps -p %d -o rss,sz' % pid, shell=True,
1133+
stdout=PIPE).stdout.readlines()
1134+
mem = int(a2[1].split()[1])
1135+
elif sys.platform.startswith('darwin'):
1136+
a2 = Popen('ps -p %d -o rss,vsz' % pid, shell=True,
1137+
stdout=PIPE).stdout.readlines()
1138+
mem = int(a2[1].split()[0])
1139+
elif sys.platform.startswith('win'):
1140+
try:
1141+
a2 = Popen(["tasklist", "/nh", "/fi", "pid eq %d" % pid],
1142+
stdout=PIPE).stdout.read()
1143+
except OSError:
1144+
raise NotImplementedError(
1145+
"report_memory works on Windows only if "
1146+
"the 'tasklist' program is found")
1147+
mem = int(a2.strip().split()[-2].replace(',', ''))
1148+
else:
1149+
raise NotImplementedError(
1150+
"We don't have a memory monitor for %s" % sys.platform)
1151+
return mem
1152+
1153+
1154+
def print_cycles(objects, outstream=sys.stdout, show_progress=False):
1155+
"""
1156+
*objects*
1157+
A list of objects to find cycles in. It is often useful to
1158+
pass in gc.garbage to find the cycles that are preventing some
1159+
objects from being garbage collected.
1160+
1161+
*outstream*
1162+
The stream for output.
1163+
1164+
*show_progress*
1165+
If True, print the number of objects reached as they are found.
1166+
"""
1167+
import gc
1168+
from types import FrameType
1169+
1170+
def print_path(path):
1171+
for i, step in enumerate(path):
1172+
# next "wraps around"
1173+
next = path[(i + 1) % len(path)]
1174+
1175+
outstream.write(" %s -- " % str(type(step)))
1176+
if isinstance(step, dict):
1177+
for key, val in step.iteritems():
1178+
if val is next:
1179+
outstream.write("[%s]" % repr(key))
1180+
break
1181+
if key is next:
1182+
outstream.write("[key] = %s" % repr(val))
1183+
break
1184+
elif isinstance(step, list):
1185+
outstream.write("[%d]" % step.index(next))
1186+
elif isinstance(step, tuple):
1187+
outstream.write("( tuple )")
1188+
else:
1189+
outstream.write(repr(step))
1190+
outstream.write(" ->\n")
1191+
outstream.write("\n")
1192+
1193+
def recurse(obj, start, all, current_path):
1194+
if show_progress:
1195+
outstream.write("%d\r" % len(all))
1196+
1197+
all[id(obj)] = None
1198+
1199+
referents = gc.get_referents(obj)
1200+
for referent in referents:
1201+
# If we've found our way back to the start, this is
1202+
# a cycle, so print it out
1203+
if referent is start:
1204+
print_path(current_path)
1205+
1206+
# Don't go back through the original list of objects, or
1207+
# through temporary references to the object, since those
1208+
# are just an artifact of the cycle detector itself.
1209+
elif referent is objects or isinstance(referent, FrameType):
1210+
continue
1211+
1212+
# We haven't seen this object before, so recurse
1213+
elif id(referent) not in all:
1214+
recurse(referent, start, all, current_path + [obj])
1215+
1216+
for obj in objects:
1217+
outstream.write("Examining: %r\n" % (obj,))
1218+
recurse(obj, obj, {}, [])

lib/matplotlib/utils/_cbook.py

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -499,36 +499,6 @@ def finddir(o, match, case=False):
499499
return [orig for name, orig in names if name.find(match) >= 0]
500500

501501

502-
def report_memory(i=0): # argument may go away
503-
'return the memory consumed by process'
504-
from subprocess import Popen, PIPE
505-
pid = os.getpid()
506-
if sys.platform == 'sunos5':
507-
a2 = Popen('ps -p %d -o osz' % pid, shell=True,
508-
stdout=PIPE).stdout.readlines()
509-
mem = int(a2[-1].strip())
510-
elif sys.platform.startswith('linux'):
511-
a2 = Popen('ps -p %d -o rss,sz' % pid, shell=True,
512-
stdout=PIPE).stdout.readlines()
513-
mem = int(a2[1].split()[1])
514-
elif sys.platform.startswith('darwin'):
515-
a2 = Popen('ps -p %d -o rss,vsz' % pid, shell=True,
516-
stdout=PIPE).stdout.readlines()
517-
mem = int(a2[1].split()[0])
518-
elif sys.platform.startswith('win'):
519-
try:
520-
a2 = Popen(["tasklist", "/nh", "/fi", "pid eq %d" % pid],
521-
stdout=PIPE).stdout.read()
522-
except OSError:
523-
raise NotImplementedError(
524-
"report_memory works on Windows only if "
525-
"the 'tasklist' program is found")
526-
mem = int(a2.strip().split()[-2].replace(',', ''))
527-
else:
528-
raise NotImplementedError(
529-
"We don't have a memory monitor for %s" % sys.platform)
530-
return mem
531-
532502

533503
class MemoryMonitor:
534504
def __init__(self, nmax=20000):
@@ -582,72 +552,6 @@ def plot(self, i0=0, isub=1, fig=None):
582552
fig.canvas.draw()
583553

584554

585-
def print_cycles(objects, outstream=sys.stdout, show_progress=False):
586-
"""
587-
*objects*
588-
A list of objects to find cycles in. It is often useful to
589-
pass in gc.garbage to find the cycles that are preventing some
590-
objects from being garbage collected.
591-
592-
*outstream*
593-
The stream for output.
594-
595-
*show_progress*
596-
If True, print the number of objects reached as they are found.
597-
"""
598-
import gc
599-
from types import FrameType
600-
601-
def print_path(path):
602-
for i, step in enumerate(path):
603-
# next "wraps around"
604-
next = path[(i + 1) % len(path)]
605-
606-
outstream.write(" %s -- " % str(type(step)))
607-
if isinstance(step, dict):
608-
for key, val in step.iteritems():
609-
if val is next:
610-
outstream.write("[%s]" % repr(key))
611-
break
612-
if key is next:
613-
outstream.write("[key] = %s" % repr(val))
614-
break
615-
elif isinstance(step, list):
616-
outstream.write("[%d]" % step.index(next))
617-
elif isinstance(step, tuple):
618-
outstream.write("( tuple )")
619-
else:
620-
outstream.write(repr(step))
621-
outstream.write(" ->\n")
622-
outstream.write("\n")
623-
624-
def recurse(obj, start, all, current_path):
625-
if show_progress:
626-
outstream.write("%d\r" % len(all))
627-
628-
all[id(obj)] = None
629-
630-
referents = gc.get_referents(obj)
631-
for referent in referents:
632-
# If we've found our way back to the start, this is
633-
# a cycle, so print it out
634-
if referent is start:
635-
print_path(current_path)
636-
637-
# Don't go back through the original list of objects, or
638-
# through temporary references to the object, since those
639-
# are just an artifact of the cycle detector itself.
640-
elif referent is objects or isinstance(referent, FrameType):
641-
continue
642-
643-
# We haven't seen this object before, so recurse
644-
elif id(referent) not in all:
645-
recurse(referent, start, all, current_path + [obj])
646-
647-
for obj in objects:
648-
outstream.write("Examining: %r\n" % (obj,))
649-
recurse(obj, obj, {}, [])
650-
651555

652556
def recursive_remove(path):
653557
if os.path.isdir(path):

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw):
568568
if kw:
569569
raise ValueError("unrecognized kwargs: %s" % kw.keys())
570570

571-
if right is None and cbook.iterable(left):
571+
if right is None and utils.iterable(left):
572572
left, right = left
573573

574574
self._process_unit_info(xdata=(left, right))
@@ -623,7 +623,7 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
623623
if kw:
624624
raise ValueError("unrecognized kwargs: %s" % kw.keys())
625625

626-
if top is None and cbook.iterable(bottom):
626+
if top is None and utils.iterable(bottom):
627627
bottom, top = bottom
628628

629629
self._process_unit_info(ydata=(bottom, top))
@@ -677,7 +677,7 @@ def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
677677
if kw:
678678
raise ValueError("unrecognized kwargs: %s" % kw.keys())
679679

680-
if top is None and cbook.iterable(bottom):
680+
if top is None and utils.iterable(bottom):
681681
bottom, top = bottom
682682

683683
self._process_unit_info(zdata=(bottom, top))
@@ -1425,7 +1425,7 @@ def set_zbound(self, lower=None, upper=None):
14251425
.. versionadded :: 1.1.0
14261426
This function was added, but not tested. Please report any bugs.
14271427
"""
1428-
if upper is None and cbook.iterable(lower):
1428+
if upper is None and utis.iterable(lower):
14291429
lower,upper = lower
14301430

14311431
old_lower,old_upper = self.get_zbound()

unit/memleak_gui.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
The default number of loops typically will not yield a stable
1212
estimate--for that you may need many hundreds of loops and some patience.
1313
14-
You may need to edit cbook.report_memory to support your platform
14+
You may need to edit utils.report_memory to support your platform
1515
1616
'''
1717
from __future__ import print_function
@@ -48,7 +48,7 @@
4848
if options.backend:
4949
matplotlib.use(options.backend)
5050
import pylab
51-
import matplotlib.cbook as cbook
51+
import matplotlib.utils as utils
5252

5353
print('# columns are: iteration, OS memory (k), number of python objects')
5454
print('#')
@@ -59,7 +59,7 @@
5959
fig.clf()
6060
pylab.close(fig)
6161
gc.collect()
62-
val = cbook.report_memory(i)
62+
val = utils.report_memory(i)
6363
if options.verbose:
6464
if i % 10 == 0:
6565
#print ("iter: %4d OS memory: %8d Python objects: %8d" %
@@ -106,4 +106,4 @@
106106
print('# Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart)))
107107

108108
if options.cycles:
109-
cbook.print_cycles(gc.garbage)
109+
utils.print_cycles(gc.garbage)

unit/memleak_hawaii3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import matplotlib
77
matplotlib.use('PDF')
88

9-
from matplotlib.cbook import report_memory
9+
from matplotlib.utils import report_memory
1010
import numpy as np
1111
from pylab import figure, show, close
1212

unit/memleak_nongui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os,matplotlib
33
matplotlib.use('Agg')
44
from matplotlib.figure import Figure
5-
from matplotlib.cbook import report_memory
5+
from matplotlib.utils import report_memory
66

77
def plot():
88
fig = Figure()

0 commit comments

Comments
 (0)