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

Skip to content

Commit af944c7

Browse files
committed
Define pyplot.__all__.
1 parent 1a8c7f3 commit af944c7

File tree

1 file changed

+33
-63
lines changed

1 file changed

+33
-63
lines changed

lib/matplotlib/pyplot.py

Lines changed: 33 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,26 @@
2626

2727
from cycler import cycler
2828
import matplotlib
29-
import matplotlib.colorbar
30-
from matplotlib import style
31-
from matplotlib import _pylab_helpers, interactive
32-
from matplotlib.cbook import dedent, silent_list, is_numlike
33-
from matplotlib.cbook import _string_to_bool
34-
from matplotlib.cbook import deprecated
35-
from matplotlib import docstring
29+
from matplotlib import (
30+
# submodules
31+
_pylab_helpers, cm, docstring, mlab, style,
32+
# functions
33+
get_backend, interactive, rc, rc_context,
34+
# objects
35+
rcParams, rcParamsDefault)
36+
from matplotlib.artist import getp, get, setp, Artist
37+
from matplotlib.axes import Axes, Subplot
3638
from matplotlib.backend_bases import FigureCanvasBase
39+
from matplotlib.cbook import (
40+
_string_to_bool, dedent, deprecated, is_numlike, silent_list)
41+
from matplotlib.cm import get_cmap, register_cmap
3742
from matplotlib.figure import Figure, figaspect
3843
from matplotlib.gridspec import GridSpec
39-
from matplotlib.image import imread as _imread
40-
from matplotlib.image import imsave as _imsave
41-
from matplotlib import rcParams, rcParamsDefault, get_backend
42-
from matplotlib import rc_context
43-
from matplotlib.rcsetup import interactive_bk as _interactive_bk
44-
from matplotlib.artist import getp, get, Artist
45-
from matplotlib.artist import setp as _setp
46-
from matplotlib.axes import Axes, Subplot
44+
from matplotlib.image import imread, imsave
4745
from matplotlib.projections import PolarAxes
48-
from matplotlib import mlab # for csv2rec, detrend_none, window_hanning
46+
from matplotlib.rcsetup import interactive_bk as _interactive_bk
4947
from matplotlib.scale import get_scale_docs, get_scale_names
5048

51-
from matplotlib import cm
52-
from matplotlib.cm import get_cmap, register_cmap
53-
5449
import numpy as np
5550

5651
# We may not need the following imports here:
@@ -252,20 +247,18 @@ def show(*args, **kw):
252247

253248

254249
def isinteractive():
255-
"""
256-
Return status of interactive mode.
257-
"""
250+
"""Return status of interactive mode."""
258251
return matplotlib.is_interactive()
259252

260253

261254
def ioff():
262-
'Turn interactive mode off.'
255+
"""Turn interactive mode off."""
263256
matplotlib.interactive(False)
264257
uninstall_repl_displayhook()
265258

266259

267260
def ion():
268-
'Turn interactive mode on.'
261+
"""Turn interactive mode on."""
269262
matplotlib.interactive(True)
270263
install_repl_displayhook()
271264

@@ -294,16 +287,6 @@ def pause(interval):
294287
time.sleep(interval)
295288

296289

297-
@docstring.copy_dedent(matplotlib.rc)
298-
def rc(*args, **kwargs):
299-
matplotlib.rc(*args, **kwargs)
300-
301-
302-
@docstring.copy_dedent(matplotlib.rc_context)
303-
def rc_context(rc=None, fname=None):
304-
return matplotlib.rc_context(rc, fname)
305-
306-
307290
@docstring.copy_dedent(matplotlib.rcdefaults)
308291
def rcdefaults():
309292
matplotlib.rcdefaults()
@@ -325,10 +308,6 @@ def sci(im):
325308

326309

327310
## Any Artist ##
328-
# (getp is simply imported)
329-
@docstring.copy(_setp)
330-
def setp(*args, **kwargs):
331-
return _setp(*args, **kwargs)
332311

333312

334313
def xkcd(scale=1, length=100, randomness=2):
@@ -1339,10 +1318,9 @@ def plotting():
13391318
pass
13401319

13411320

1321+
@deprecated('2.2')
13421322
def get_plot_commands():
1343-
"""
1344-
Get a sorted list of all of the plotting commands.
1345-
"""
1323+
"""Get a sorted list of all of the plotting commands."""
13461324
# This works by searching for all functions in this module and
13471325
# removing a few hard-coded exclusions, as well as all of the
13481326
# colormap-setting functions, and anything marked as private with
@@ -1351,17 +1329,7 @@ def get_plot_commands():
13511329
exclude = {'colormaps', 'colors', 'connect', 'disconnect',
13521330
'get_plot_commands', 'get_current_fig_manager', 'ginput',
13531331
'plotting', 'waitforbuttonpress'}
1354-
exclude |= set(colormaps())
1355-
this_module = inspect.getmodule(get_plot_commands)
1356-
1357-
commands = set()
1358-
for name, obj in list(six.iteritems(globals())):
1359-
if name.startswith('_') or name in exclude:
1360-
continue
1361-
if inspect.isfunction(obj) and inspect.getmodule(obj) is this_module:
1362-
commands.add(name)
1363-
1364-
return sorted(commands)
1332+
return sorted(set(__all__) - exclude - set(colormaps()))
13651333

13661334

13671335
@deprecated('2.1')
@@ -1669,7 +1637,13 @@ def pad(s, l):
16691637
return s[:l]
16701638
return s + ' ' * (l - len(s))
16711639

1672-
commands = get_plot_commands()
1640+
# Searching for all public functions in this module (this is done when
1641+
# defining __all__) and remove a few hard-coded exclusions, as well as all
1642+
# of the colormap-setting functions
1643+
exclude = {"colormaps", "colors", "connect", "disconnect",
1644+
"get_current_fig_manager", "ginput", "plotting",
1645+
"waitforbuttonpress"}
1646+
commands = sorted(set(__all__) - exclude - set(colormaps()))
16731647

16741648
first_sentence = re.compile(r"(?:\s*).+?\.(?:\s+|$)", flags=re.DOTALL)
16751649

@@ -1766,16 +1740,6 @@ def set_cmap(cmap):
17661740
im.set_cmap(cmap)
17671741

17681742

1769-
@docstring.copy_dedent(_imread)
1770-
def imread(*args, **kwargs):
1771-
return _imread(*args, **kwargs)
1772-
1773-
1774-
@docstring.copy_dedent(_imsave)
1775-
def imsave(*args, **kwargs):
1776-
return _imsave(*args, **kwargs)
1777-
1778-
17791743
def matshow(A, fignum=None, **kw):
17801744
"""
17811745
Display an array as a matrix in a new figure window.
@@ -2073,4 +2037,10 @@ def func():
20732037
_make_cmap_wrapper(_cmap)
20742038

20752039

2040+
__all__ = sorted([name for name, obj in globals().items()
2041+
if getattr(obj, "__module__", None) == __name__
2042+
and not name.startswith("_")]
2043+
+ ["getp", "imread", "imsave", "rc", "rc_context", "setp"])
2044+
2045+
20762046
_setup_pyplot_info_docstrings()

0 commit comments

Comments
 (0)