@@ -997,8 +997,8 @@ def figure(
997997 root_fig = num .get_figure (root = True )
998998 if root_fig .canvas .manager is None :
999999 raise ValueError ("The passed figure is not managed by pyplot" )
1000- elif any ([figsize , dpi , facecolor , edgecolor , not frameon ,
1001- kwargs ] ) and root_fig .canvas .manager .num in allnums :
1000+ elif ( any (param is not None for param in [figsize , dpi , facecolor , edgecolor ])
1001+ or not frameon or kwargs ) and root_fig .canvas .manager .num in allnums :
10021002 _api .warn_external (
10031003 "Ignoring specified arguments in this call because figure "
10041004 f"with num: { root_fig .canvas .manager .num } already exists" )
@@ -1010,8 +1010,8 @@ def figure(
10101010 if num is None :
10111011 num = next_num
10121012 else :
1013- if any ([figsize , dpi , facecolor , edgecolor , not frameon ,
1014- kwargs ] ) and num in allnums :
1013+ if ( any (param is not None for param in [figsize , dpi , facecolor , edgecolor ])
1014+ or not frameon or kwargs ) and num in allnums :
10151015 _api .warn_external (
10161016 "Ignoring specified arguments in this call "
10171017 f"because figure with num: { num } already exists" )
@@ -2663,9 +2663,13 @@ def matshow(A: ArrayLike, fignum: None | int = None, **kwargs) -> AxesImage:
26632663 if fignum == 0 :
26642664 ax = gca ()
26652665 else :
2666- # Extract actual aspect ratio of array and make appropriately sized
2667- # figure.
2668- fig = figure (fignum , figsize = figaspect (A ))
2666+ if fignum is not None and fignum_exists (fignum ):
2667+ # Do not try to set a figure size.
2668+ figsize = None
2669+ else :
2670+ # Extract actual aspect ratio of array and make appropriately sized figure.
2671+ figsize = figaspect (A )
2672+ fig = figure (fignum , figsize = figsize )
26692673 ax = fig .add_axes ((0.15 , 0.09 , 0.775 , 0.775 ))
26702674 im = ax .matshow (A , ** kwargs )
26712675 sci (im )
0 commit comments