@@ -994,8 +994,8 @@ def figure(
994994 root_fig = num .get_figure (root = True )
995995 if root_fig .canvas .manager is None :
996996 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 :
999999 _api .warn_external (
10001000 "Ignoring specified arguments in this call because figure "
10011001 f"with num: { root_fig .canvas .manager .num } already exists" )
@@ -1007,8 +1007,8 @@ def figure(
10071007 if num is None :
10081008 num = next_num
10091009 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 :
10121012 _api .warn_external (
10131013 "Ignoring specified arguments in this call "
10141014 f"because figure with num: { num } already exists" )
@@ -2662,9 +2662,13 @@ def matshow(A: ArrayLike, fignum: None | int = None, **kwargs) -> AxesImage:
26622662 if fignum == 0 :
26632663 ax = gca ()
26642664 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 )
26682672 ax = fig .add_axes ((0.15 , 0.09 , 0.775 , 0.775 ))
26692673 im = ax .matshow (A , ** kwargs )
26702674 sci (im )
0 commit comments