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

Skip to content

Commit 24e59a6

Browse files
committed
Define pyplot.__all__.
1 parent cf09ff8 commit 24e59a6

File tree

1 file changed

+34
-65
lines changed

1 file changed

+34
-65
lines changed

lib/matplotlib/pyplot.py

Lines changed: 34 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,26 @@
2727

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

52-
from matplotlib import cm
53-
from matplotlib.cm import get_cmap, register_cmap
54-
5550
import numpy as np
5651

5752
# We may not need the following imports here:
@@ -253,9 +248,7 @@ def show(*args, **kw):
253248

254249

255250
def isinteractive():
256-
"""
257-
Return status of interactive mode.
258-
"""
251+
"""Return status of interactive mode."""
259252
return matplotlib.is_interactive()
260253

261254

@@ -297,16 +290,6 @@ def pause(interval):
297290
time.sleep(interval)
298291

299292

300-
@docstring.copy_dedent(matplotlib.rc)
301-
def rc(*args, **kwargs):
302-
matplotlib.rc(*args, **kwargs)
303-
304-
305-
@docstring.copy_dedent(matplotlib.rc_context)
306-
def rc_context(rc=None, fname=None):
307-
return matplotlib.rc_context(rc, fname)
308-
309-
310293
@docstring.copy_dedent(matplotlib.rcdefaults)
311294
def rcdefaults():
312295
matplotlib.rcdefaults()
@@ -328,10 +311,6 @@ def sci(im):
328311

329312

330313
## Any Artist ##
331-
# (getp is simply imported)
332-
@docstring.copy(_setp)
333-
def setp(*args, **kwargs):
334-
return _setp(*args, **kwargs)
335314

336315

337316
def xkcd(scale=1, length=100, randomness=2):
@@ -719,10 +698,9 @@ def axes(arg=None, **kwargs):
719698
return subplot(111, **kwargs)
720699

721700
if isinstance(arg, Axes):
722-
warn_deprecated("2.2",
723-
message="Using pyplot.axes(ax) with ax an Axes "
724-
"argument is deprecated. Please use "
725-
"pyplot.sca(ax) instead.")
701+
cbook.warn_deprecated(
702+
"2.2", "Using pyplot.axes(ax) with ax an Axes argument is "
703+
"deprecated. Please use pyplot.sca(ax) instead.")
726704
ax = arg
727705
sca(ax)
728706
return ax
@@ -1351,10 +1329,9 @@ def plotting():
13511329
pass
13521330

13531331

1332+
@deprecated('2.2')
13541333
def get_plot_commands():
1355-
"""
1356-
Get a sorted list of all of the plotting commands.
1357-
"""
1334+
"""Get a sorted list of all of the plotting commands."""
13581335
# This works by searching for all functions in this module and
13591336
# removing a few hard-coded exclusions, as well as all of the
13601337
# colormap-setting functions, and anything marked as private with
@@ -1363,17 +1340,7 @@ def get_plot_commands():
13631340
exclude = {'colormaps', 'colors', 'connect', 'disconnect',
13641341
'get_plot_commands', 'get_current_fig_manager', 'ginput',
13651342
'plotting', 'waitforbuttonpress'}
1366-
exclude |= set(colormaps())
1367-
this_module = inspect.getmodule(get_plot_commands)
1368-
1369-
commands = set()
1370-
for name, obj in list(six.iteritems(globals())):
1371-
if name.startswith('_') or name in exclude:
1372-
continue
1373-
if inspect.isfunction(obj) and inspect.getmodule(obj) is this_module:
1374-
commands.add(name)
1375-
1376-
return sorted(commands)
1343+
return sorted(set(__all__) - exclude - set(colormaps()))
13771344

13781345

13791346
@deprecated('2.1')
@@ -1681,7 +1648,13 @@ def pad(s, l):
16811648
return s[:l]
16821649
return s + ' ' * (l - len(s))
16831650

1684-
commands = get_plot_commands()
1651+
# Searching for all public functions in this module (this is done when
1652+
# defining __all__) and remove a few hard-coded exclusions, as well as all
1653+
# of the colormap-setting functions
1654+
exclude = {"colormaps", "colors", "connect", "disconnect",
1655+
"get_current_fig_manager", "ginput", "plotting",
1656+
"waitforbuttonpress"}
1657+
commands = sorted(set(__all__) - exclude - set(colormaps()))
16851658

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

@@ -1778,16 +1751,6 @@ def set_cmap(cmap):
17781751
im.set_cmap(cmap)
17791752

17801753

1781-
@docstring.copy_dedent(_imread)
1782-
def imread(*args, **kwargs):
1783-
return _imread(*args, **kwargs)
1784-
1785-
1786-
@docstring.copy_dedent(_imsave)
1787-
def imsave(*args, **kwargs):
1788-
return _imsave(*args, **kwargs)
1789-
1790-
17911754
def matshow(A, fignum=None, **kw):
17921755
"""
17931756
Display an array as a matrix in a new figure window.
@@ -2085,4 +2048,10 @@ def func():
20852048
_make_cmap_wrapper(_cmap)
20862049

20872050

2051+
__all__ = sorted([name for name, obj in globals().items()
2052+
if getattr(obj, "__module__", None) == __name__
2053+
and not name.startswith("_")]
2054+
+ ["getp", "imread", "imsave", "rc", "rc_context", "setp"])
2055+
2056+
20882057
_setup_pyplot_info_docstrings()

0 commit comments

Comments
 (0)