@@ -608,49 +608,46 @@ def disconnect(cid):
608
608
return get_current_fig_manager ().canvas .mpl_disconnect (cid )
609
609
610
610
611
- def close (* args ):
611
+ def close (fig = None ):
612
612
"""
613
613
Close a figure window.
614
614
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:
620
619
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
622
625
623
- ``close('all')`` closes all the figure windows
624
626
"""
625
-
626
- if len (args ) == 0 :
627
+ if fig is None :
627
628
figManager = _pylab_helpers .Gcf .get_active ()
628
629
if figManager is None :
629
630
return
630
631
else :
631
632
_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 )
652
648
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'" )
654
651
655
652
656
653
def clf ():
0 commit comments