Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit52ce211

Browse files
authored
Merge pull request#29546 from rcomer/matshow
FIX: pyplot.matshow figure handling
2 parents7285029 +c281070 commit52ce211

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

‎lib/matplotlib/pyplot.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,8 @@ def figure(
997997
root_fig=num.get_figure(root=True)
998998
ifroot_fig.canvas.managerisNone:
999999
raiseValueError("The passed figure is not managed by pyplot")
1000-
elifany([figsize,dpi,facecolor,edgecolor,notframeon,
1001-
kwargs])androot_fig.canvas.manager.numinallnums:
1000+
elif(any(paramisnotNoneforparamin[figsize,dpi,facecolor,edgecolor])
1001+
ornotframeonorkwargs)androot_fig.canvas.manager.numinallnums:
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
ifnumisNone:
10111011
num=next_num
10121012
else:
1013-
ifany([figsize,dpi,facecolor,edgecolor,notframeon,
1014-
kwargs])andnuminallnums:
1013+
if(any(paramisnotNoneforparamin[figsize,dpi,facecolor,edgecolor])
1014+
ornotframeonorkwargs)andnuminallnums:
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
iffignum==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+
iffignumisnotNoneandfignum_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)

‎lib/matplotlib/tests/test_pyplot.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,13 @@ def test_figure_hook():
460460

461461

462462
deftest_multiple_same_figure_calls():
463-
fig=mpl.pyplot.figure(1,figsize=(1,2))
463+
fig=plt.figure(1,figsize=(1,2))
464464
withpytest.warns(UserWarning,match="Ignoring specified arguments in this call"):
465-
fig2=mpl.pyplot.figure(1,figsize=(3,4))
465+
fig2=plt.figure(1,figsize=np.array([3,4]))
466466
withpytest.warns(UserWarning,match="Ignoring specified arguments in this call"):
467-
mpl.pyplot.figure(fig,figsize=(5,6))
467+
plt.figure(fig,figsize=np.array([5,6]))
468468
assertfigisfig2
469-
fig3=mpl.pyplot.figure(1)# Checks for false warnings
469+
fig3=plt.figure(1)# Checks for false warnings
470470
assertfigisfig3
471471

472472

@@ -476,3 +476,11 @@ def test_close_all_warning():
476476
# Check that the warning is issued when 'all' is passed to plt.figure
477477
withpytest.warns(UserWarning,match="closes all existing figures"):
478478
fig2=plt.figure("all")
479+
480+
481+
deftest_matshow():
482+
fig=plt.figure()
483+
arr= [[0,1], [1,2]]
484+
485+
# Smoke test that matshow does not ask for a new figsize on the existing figure
486+
plt.matshow(arr,fignum=fig.number)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp