@@ -622,63 +622,49 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
622622 in the matplotlibrc file.
623623 """
624624
625- if figsize is None :
626- figsize = rcParams ['figure.figsize' ]
627- if dpi is None :
628- dpi = rcParams ['figure.dpi' ]
629- if facecolor is None :
630- facecolor = rcParams ['figure.facecolor' ]
631- if edgecolor is None :
632- edgecolor = rcParams ['figure.edgecolor' ]
633-
634625 allnums = get_fignums ()
635626 next_num = max (allnums ) + 1 if allnums else 1
636- figLabel = ''
627+ fig_label = ''
637628 if num is None :
638629 num = next_num
639630 elif isinstance (num , str ):
640- figLabel = num
641- allLabels = get_figlabels ()
642- if figLabel not in allLabels :
643- if figLabel == 'all' :
631+ fig_label = num
632+ all_labels = get_figlabels ()
633+ if fig_label not in all_labels :
634+ if fig_label == 'all' :
644635 cbook ._warn_external (
645- "close('all') closes all existing figures" )
636+ "close('all') closes all existing figures. " )
646637 num = next_num
647638 else :
648- inum = allLabels .index (figLabel )
639+ inum = all_labels .index (fig_label )
649640 num = allnums [inum ]
650641 else :
651642 num = int (num ) # crude validation of num argument
652643
653- figManager = _pylab_helpers .Gcf .get_fig_manager (num )
654- if figManager is None :
644+ manager = _pylab_helpers .Gcf .get_fig_manager (num )
645+ if manager is None :
655646 max_open_warning = rcParams ['figure.max_open_warning' ]
656-
657647 if len (allnums ) == max_open_warning >= 1 :
658648 cbook ._warn_external (
659- "More than %d figures have been opened. Figures "
660- "created through the pyplot interface "
661- "(`matplotlib.pyplot.figure`) are retained until "
662- "explicitly closed and may consume too much memory. "
663- "(To control this warning, see the rcParam "
664- "`figure.max_open_warning`)." %
665- max_open_warning , RuntimeWarning )
649+ f"More than { max_open_warning } figures have been opened. "
650+ f"Figures created through the pyplot interface "
651+ f"(`matplotlib.pyplot.figure`) are retained until explicitly "
652+ f"closed and may consume too much memory. (To control this "
653+ f"warning, see the rcParam `figure.max_open_warning`)." ,
654+ RuntimeWarning )
666655
667656 if get_backend ().lower () == 'ps' :
668657 dpi = 72
669658
670- figManager = new_figure_manager (num , figsize = figsize ,
671- dpi = dpi ,
672- facecolor = facecolor ,
673- edgecolor = edgecolor ,
674- frameon = frameon ,
675- FigureClass = FigureClass ,
676- ** kwargs )
677- fig = figManager .canvas .figure
678- if figLabel :
679- fig .set_label (figLabel )
659+ manager = new_figure_manager (
660+ num , figsize = figsize , dpi = dpi ,
661+ facecolor = facecolor , edgecolor = edgecolor , frameon = frameon ,
662+ FigureClass = FigureClass , ** kwargs )
663+ fig = manager .canvas .figure
664+ if fig_label :
665+ fig .set_label (fig_label )
680666
681- _pylab_helpers .Gcf ._set_new_active_manager (figManager )
667+ _pylab_helpers .Gcf ._set_new_active_manager (manager )
682668
683669 # make sure backends (inline) that we don't ship that expect this
684670 # to be called in plotting commands to make the figure call show
@@ -690,9 +676,9 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
690676 fig .stale_callback = _auto_draw_if_interactive
691677
692678 if clear :
693- figManager .canvas .figure .clear ()
679+ manager .canvas .figure .clear ()
694680
695- return figManager .canvas .figure
681+ return manager .canvas .figure
696682
697683
698684def _auto_draw_if_interactive (fig , val ):
@@ -723,9 +709,9 @@ def gcf():
723709 If no current figure exists, a new one is created using
724710 `~.pyplot.figure()`.
725711 """
726- figManager = _pylab_helpers .Gcf .get_active ()
727- if figManager is not None :
728- return figManager .canvas .figure
712+ manager = _pylab_helpers .Gcf .get_active ()
713+ if manager is not None :
714+ return manager .canvas .figure
729715 else :
730716 return figure ()
731717
@@ -742,9 +728,9 @@ def get_fignums():
742728
743729def get_figlabels ():
744730 """Return a list of existing figure labels."""
745- figManagers = _pylab_helpers .Gcf .get_all_fig_managers ()
746- figManagers .sort (key = lambda m : m .num )
747- return [m .canvas .figure .get_label () for m in figManagers ]
731+ managers = _pylab_helpers .Gcf .get_all_fig_managers ()
732+ managers .sort (key = lambda m : m .num )
733+ return [m .canvas .figure .get_label () for m in managers ]
748734
749735
750736def get_current_fig_manager ():
@@ -791,11 +777,11 @@ def close(fig=None):
791777
792778 """
793779 if fig is None :
794- figManager = _pylab_helpers .Gcf .get_active ()
795- if figManager is None :
780+ manager = _pylab_helpers .Gcf .get_active ()
781+ if manager is None :
796782 return
797783 else :
798- _pylab_helpers .Gcf .destroy (figManager )
784+ _pylab_helpers .Gcf .destroy (manager )
799785 elif fig == 'all' :
800786 _pylab_helpers .Gcf .destroy_all ()
801787 elif isinstance (fig , int ):
@@ -805,9 +791,9 @@ def close(fig=None):
805791 # can use its integer representation
806792 _pylab_helpers .Gcf .destroy (fig .int )
807793 elif isinstance (fig , str ):
808- allLabels = get_figlabels ()
809- if fig in allLabels :
810- num = get_fignums ()[allLabels .index (fig )]
794+ all_labels = get_figlabels ()
795+ if fig in all_labels :
796+ num = get_fignums ()[all_labels .index (fig )]
811797 _pylab_helpers .Gcf .destroy (num )
812798 elif isinstance (fig , Figure ):
813799 _pylab_helpers .Gcf .destroy_fig (fig )
0 commit comments