@@ -994,8 +994,8 @@ def figure(
994
994
root_fig = num .get_figure (root = True )
995
995
if root_fig .canvas .manager is None :
996
996
raise ValueError ("The passed figure is not managed by pyplot" )
997
- elif any ([figsize , dpi , facecolor , edgecolor , not frameon ,
998
- kwargs ] ) and root_fig .canvas .manager .num in allnums :
997
+ elif ( any (param is not None for param in [figsize , dpi , facecolor , edgecolor ])
998
+ or not frameon or kwargs ) and root_fig .canvas .manager .num in allnums :
999
999
_api .warn_external (
1000
1000
"Ignoring specified arguments in this call because figure "
1001
1001
f"with num: { root_fig .canvas .manager .num } already exists" )
@@ -1007,8 +1007,8 @@ def figure(
1007
1007
if num is None :
1008
1008
num = next_num
1009
1009
else :
1010
- if any ([figsize , dpi , facecolor , edgecolor , not frameon ,
1011
- kwargs ] ) and num in allnums :
1010
+ if ( any (param is not None for param in [figsize , dpi , facecolor , edgecolor ])
1011
+ or not frameon or kwargs ) and num in allnums :
1012
1012
_api .warn_external (
1013
1013
"Ignoring specified arguments in this call "
1014
1014
f"because figure with num: { num } already exists" )
@@ -2662,9 +2662,13 @@ def matshow(A: ArrayLike, fignum: None | int = None, **kwargs) -> AxesImage:
2662
2662
if fignum == 0 :
2663
2663
ax = gca ()
2664
2664
else :
2665
- # Extract actual aspect ratio of array and make appropriately sized
2666
- # figure.
2667
- fig = figure (fignum , figsize = figaspect (A ))
2665
+ if fignum is not None and fignum_exists (fignum ):
2666
+ # Do not try to set a figure size.
2667
+ figsize = None
2668
+ else :
2669
+ # Extract actual aspect ratio of array and make appropriately sized figure.
2670
+ figsize = figaspect (A )
2671
+ fig = figure (fignum , figsize = figsize )
2668
2672
ax = fig .add_axes ((0.15 , 0.09 , 0.775 , 0.775 ))
2669
2673
im = ax .matshow (A , ** kwargs )
2670
2674
sci (im )
0 commit comments