Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f6bdcb5

Browse filesBrowse files
committed
Update pyplot.close docstring
1 parent 9fc98c9 commit f6bdcb5
Copy full SHA for f6bdcb5

File tree

Expand file treeCollapse file tree

1 file changed

+28
-31
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-31
lines changed

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+28-31Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -608,49 +608,46 @@ def disconnect(cid):
608608
return get_current_fig_manager().canvas.mpl_disconnect(cid)
609609

610610

611-
def close(*args):
611+
def close(fig=None):
612612
"""
613613
Close a figure window.
614614
615-
``close()`` by itself closes the current figure
616-
617-
``close(fig)`` closes the `.Figure` instance *fig*
618-
619-
``close(num)`` closes the figure number *num*
615+
Parameters
616+
----------
617+
fig : None or int or str or `.Figure`
618+
The figure to close. There are a number of ways to specify this:
620619
621-
``close(name)`` where *name* is a string, closes figure with that label
620+
- *None*: the current figure
621+
- `.Figure`: the given `.Figure` instance
622+
- ``int``: a figure number
623+
- ``str``: a figure name
624+
- 'all': all figures
622625
623-
``close('all')`` closes all the figure windows
624626
"""
625-
626-
if len(args) == 0:
627+
if fig is None:
627628
figManager = _pylab_helpers.Gcf.get_active()
628629
if figManager is None:
629630
return
630631
else:
631632
_pylab_helpers.Gcf.destroy(figManager.num)
632-
elif len(args) == 1:
633-
arg = args[0]
634-
if arg == 'all':
635-
_pylab_helpers.Gcf.destroy_all()
636-
elif isinstance(arg, int):
637-
_pylab_helpers.Gcf.destroy(arg)
638-
elif hasattr(arg, 'int'):
639-
# if we are dealing with a type UUID, we
640-
# can use its integer representation
641-
_pylab_helpers.Gcf.destroy(arg.int)
642-
elif isinstance(arg, str):
643-
allLabels = get_figlabels()
644-
if arg in allLabels:
645-
num = get_fignums()[allLabels.index(arg)]
646-
_pylab_helpers.Gcf.destroy(num)
647-
elif isinstance(arg, Figure):
648-
_pylab_helpers.Gcf.destroy_fig(arg)
649-
else:
650-
raise TypeError('Unrecognized argument type %s to close'
651-
% type(arg))
633+
elif fig == 'all':
634+
_pylab_helpers.Gcf.destroy_all()
635+
elif isinstance(fig, int):
636+
_pylab_helpers.Gcf.destroy(fig)
637+
elif hasattr(fig, 'int'):
638+
# if we are dealing with a type UUID, we
639+
# can use its integer representation
640+
_pylab_helpers.Gcf.destroy(fig.int)
641+
elif isinstance(fig, str):
642+
allLabels = get_figlabels()
643+
if fig in allLabels:
644+
num = get_fignums()[allLabels.index(fig)]
645+
_pylab_helpers.Gcf.destroy(num)
646+
elif isinstance(fig, Figure):
647+
_pylab_helpers.Gcf.destroy_fig(fig)
652648
else:
653-
raise TypeError('close takes 0 or 1 arguments')
649+
raise TypeError("close() argument must be a Figure, an int, a string, "
650+
"or None, not '%s'")
654651

655652

656653
def clf():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.