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

Skip to content

Commit 7a99bec

Browse files
committed
Define pyplot.__all__.
1 parent e6162fb commit 7a99bec

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
@@ -25,31 +25,26 @@
2525

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

50-
from matplotlib import cm
51-
from matplotlib.cm import get_cmap, register_cmap
52-
5348
import numpy as np
5449

5550
# 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

@@ -303,16 +296,6 @@ def pause(interval):
303296
time.sleep(interval)
304297

305298

306-
@docstring.copy_dedent(matplotlib.rc)
307-
def rc(*args, **kwargs):
308-
matplotlib.rc(*args, **kwargs)
309-
310-
311-
@docstring.copy_dedent(matplotlib.rc_context)
312-
def rc_context(rc=None, fname=None):
313-
return matplotlib.rc_context(rc, fname)
314-
315-
316299
@docstring.copy_dedent(matplotlib.rcdefaults)
317300
def rcdefaults():
318301
matplotlib.rcdefaults()
@@ -334,10 +317,6 @@ def sci(im):
334317

335318

336319
## Any Artist ##
337-
# (getp is simply imported)
338-
@docstring.copy(_setp)
339-
def setp(*args, **kwargs):
340-
return _setp(*args, **kwargs)
341320

342321

343322
def xkcd(scale=1, length=100, randomness=2):
@@ -1314,10 +1293,9 @@ def plotting():
13141293
pass
13151294

13161295

1296+
@deprecated('2.2')
13171297
def get_plot_commands():
1318-
"""
1319-
Get a sorted list of all of the plotting commands.
1320-
"""
1298+
"""Get a sorted list of all of the plotting commands."""
13211299
# This works by searching for all functions in this module and
13221300
# removing a few hard-coded exclusions, as well as all of the
13231301
# colormap-setting functions, and anything marked as private with
@@ -1326,17 +1304,7 @@ def get_plot_commands():
13261304
exclude = {'colormaps', 'colors', 'connect', 'disconnect',
13271305
'get_plot_commands', 'get_current_fig_manager', 'ginput',
13281306
'plotting', 'waitforbuttonpress'}
1329-
exclude |= set(colormaps())
1330-
this_module = inspect.getmodule(get_plot_commands)
1331-
1332-
commands = set()
1333-
for name, obj in list(six.iteritems(globals())):
1334-
if name.startswith('_') or name in exclude:
1335-
continue
1336-
if inspect.isfunction(obj) and inspect.getmodule(obj) is this_module:
1337-
commands.add(name)
1338-
1339-
return sorted(commands)
1307+
return sorted(set(__all__) - exclude - set(colormaps()))
13401308

13411309

13421310
@deprecated('2.1')
@@ -1644,7 +1612,13 @@ def pad(s, l):
16441612
return s[:l]
16451613
return s + ' ' * (l - len(s))
16461614

1647-
commands = get_plot_commands()
1615+
# Searching for all public functions in this module (this is done when
1616+
# defining __all__) and remove a few hard-coded exclusions, as well as all
1617+
# of the colormap-setting functions
1618+
exclude = {"colormaps", "colors", "connect", "disconnect",
1619+
"get_current_fig_manager", "ginput", "plotting",
1620+
"waitforbuttonpress"}
1621+
commands = sorted(set(__all__) - exclude - set(colormaps()))
16481622

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

@@ -1741,16 +1715,6 @@ def set_cmap(cmap):
17411715
im.set_cmap(cmap)
17421716

17431717

1744-
@docstring.copy_dedent(_imread)
1745-
def imread(*args, **kwargs):
1746-
return _imread(*args, **kwargs)
1747-
1748-
1749-
@docstring.copy_dedent(_imsave)
1750-
def imsave(*args, **kwargs):
1751-
return _imsave(*args, **kwargs)
1752-
1753-
17541718
def matshow(A, fignum=None, **kw):
17551719
"""
17561720
Display an array as a matrix in a new figure window.
@@ -2048,4 +2012,10 @@ def func():
20482012
_make_cmap_wrapper(_cmap)
20492013

20502014

2015+
__all__ = sorted([name for name, obj in globals().items()
2016+
if getattr(obj, "__module__", None) == __name__
2017+
and not name.startswith("_")]
2018+
+ ["getp", "imread", "imsave", "rc", "rc_context", "setp"])
2019+
2020+
20512021
_setup_pyplot_info_docstrings()

0 commit comments

Comments
 (0)