@@ -983,30 +983,42 @@ def figure(
983
983
`~matplotlib.rcParams` defines the default values, which can be modified
984
984
in the matplotlibrc file.
985
985
"""
986
+ allnums = get_fignums ()
987
+
986
988
if isinstance (num , FigureBase ):
987
989
# type narrowed to `Figure | SubFigure` by combination of input and isinstance
988
990
if num .canvas .manager is None :
989
991
raise ValueError ("The passed figure is not managed by pyplot" )
992
+ elif any ([figsize , dpi , facecolor , edgecolor , not frameon ,
993
+ kwargs ]) and num .canvas .manager .num in allnums :
994
+ _api .warn_external (
995
+ "Ignoring specified arguments in this call "
996
+ f"because figure with num: { num .canvas .manager .num } already exists" )
990
997
_pylab_helpers .Gcf .set_active (num .canvas .manager )
991
998
return num .figure
992
999
993
- allnums = get_fignums ()
994
1000
next_num = max (allnums ) + 1 if allnums else 1
995
1001
fig_label = ''
996
1002
if num is None :
997
1003
num = next_num
998
- elif isinstance (num , str ):
999
- fig_label = num
1000
- all_labels = get_figlabels ()
1001
- if fig_label not in all_labels :
1002
- if fig_label == 'all' :
1003
- _api .warn_external ("close('all') closes all existing figures." )
1004
- num = next_num
1005
- else :
1006
- inum = all_labels .index (fig_label )
1007
- num = allnums [inum ]
1008
1004
else :
1009
- num = int (num ) # crude validation of num argument
1005
+ if any ([figsize , dpi , facecolor , edgecolor , not frameon ,
1006
+ kwargs ]) and num in allnums :
1007
+ _api .warn_external (
1008
+ "Ignoring specified arguments in this call "
1009
+ f"because figure with num: { num } already exists" )
1010
+ if isinstance (num , str ):
1011
+ fig_label = num
1012
+ all_labels = get_figlabels ()
1013
+ if fig_label not in all_labels :
1014
+ if fig_label == 'all' :
1015
+ _api .warn_external ("close('all') closes all existing figures." )
1016
+ num = next_num
1017
+ else :
1018
+ inum = all_labels .index (fig_label )
1019
+ num = allnums [inum ]
1020
+ else :
1021
+ num = int (num ) # crude validation of num argument
1010
1022
1011
1023
# Type of "num" has narrowed to int, but mypy can't quite see it
1012
1024
manager = _pylab_helpers .Gcf .get_fig_manager (num ) # type: ignore[arg-type]
0 commit comments