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

Commitb17774c

Browse files
authored
Merge pull request#29555 from meeseeksmachine/auto-backport-of-pr-29546-on-v3.10.x
Backport PR#29546 on branch v3.10.x (FIX: pyplot.matshow figure handling)
2 parentsab1e0a5 +edf8076 commitb17774c

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
@@ -994,8 +994,8 @@ def figure(
994994
root_fig=num.get_figure(root=True)
995995
ifroot_fig.canvas.managerisNone:
996996
raiseValueError("The passed figure is not managed by pyplot")
997-
elifany([figsize,dpi,facecolor,edgecolor,notframeon,
998-
kwargs])androot_fig.canvas.manager.numinallnums:
997+
elif(any(paramisnotNoneforparamin[figsize,dpi,facecolor,edgecolor])
998+
ornotframeonorkwargs)androot_fig.canvas.manager.numinallnums:
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
ifnumisNone:
10081008
num=next_num
10091009
else:
1010-
ifany([figsize,dpi,facecolor,edgecolor,notframeon,
1011-
kwargs])andnuminallnums:
1010+
if(any(paramisnotNoneforparamin[figsize,dpi,facecolor,edgecolor])
1011+
ornotframeonorkwargs)andnuminallnums:
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
iffignum==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+
iffignumisnotNoneandfignum_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)

‎lib/matplotlib/tests/test_pyplot.py

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

460460

461461
deftest_multiple_same_figure_calls():
462-
fig=mpl.pyplot.figure(1,figsize=(1,2))
462+
fig=plt.figure(1,figsize=(1,2))
463463
withpytest.warns(UserWarning,match="Ignoring specified arguments in this call"):
464-
fig2=mpl.pyplot.figure(1,figsize=(3,4))
464+
fig2=plt.figure(1,figsize=np.array([3,4]))
465465
withpytest.warns(UserWarning,match="Ignoring specified arguments in this call"):
466-
mpl.pyplot.figure(fig,figsize=(5,6))
466+
plt.figure(fig,figsize=np.array([5,6]))
467467
assertfigisfig2
468-
fig3=mpl.pyplot.figure(1)# Checks for false warnings
468+
fig3=plt.figure(1)# Checks for false warnings
469469
assertfigisfig3
470470

471471

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp