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

Use explicit signature in pyplot.close() #11563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 28 additions & 31 deletions 59 lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,49 +608,46 @@ def disconnect(cid):
return get_current_fig_manager().canvas.mpl_disconnect(cid)


def close(*args):
def close(fig=None):
"""
Close a figure window.

``close()`` by itself closes the current figure

``close(fig)`` closes the `.Figure` instance *fig*

``close(num)`` closes the figure number *num*
Parameters
----------
fig : None or int or str or `.Figure`
The figure to close. There are a number of ways to specify this:

``close(name)`` where *name* is a string, closes figure with that label
- *None*: the current figure
- `.Figure`: the given `.Figure` instance
- ``int``: a figure number
- ``str``: a figure name
- 'all': all figures

``close('all')`` closes all the figure windows
"""

if len(args) == 0:
if fig is None:
figManager = _pylab_helpers.Gcf.get_active()
if figManager is None:
return
else:
_pylab_helpers.Gcf.destroy(figManager.num)
elif len(args) == 1:
arg = args[0]
if arg == 'all':
_pylab_helpers.Gcf.destroy_all()
elif isinstance(arg, int):
_pylab_helpers.Gcf.destroy(arg)
elif hasattr(arg, 'int'):
# if we are dealing with a type UUID, we
# can use its integer representation
_pylab_helpers.Gcf.destroy(arg.int)
elif isinstance(arg, str):
allLabels = get_figlabels()
if arg in allLabels:
num = get_fignums()[allLabels.index(arg)]
_pylab_helpers.Gcf.destroy(num)
elif isinstance(arg, Figure):
_pylab_helpers.Gcf.destroy_fig(arg)
else:
raise TypeError('Unrecognized argument type %s to close'
% type(arg))
elif fig == 'all':
_pylab_helpers.Gcf.destroy_all()
elif isinstance(fig, int):
_pylab_helpers.Gcf.destroy(fig)
elif hasattr(fig, 'int'):
# if we are dealing with a type UUID, we
# can use its integer representation
_pylab_helpers.Gcf.destroy(fig.int)
elif isinstance(fig, str):
allLabels = get_figlabels()
if fig in allLabels:
num = get_fignums()[allLabels.index(fig)]
_pylab_helpers.Gcf.destroy(num)
elif isinstance(fig, Figure):
_pylab_helpers.Gcf.destroy_fig(fig)
else:
raise TypeError('close takes 0 or 1 arguments')
raise TypeError("close() argument must be a Figure, an int, a string, "
"or None, not '%s'")


def clf():
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.