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

Commite0de606

Browse files
authored
Merge pull request#25520 from rcomer/backport-25499
Backport PR#25499: FIX: use locators in adjust_bbox
2 parentsc37415e +a42649e commite0de606

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

‎lib/matplotlib/_tight_bbox.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def adjust_bbox(fig, bbox_inches, fixed_dpi=None):
2323
locator_list= []
2424
sentinel=object()
2525
foraxinfig.axes:
26-
locator_list.append(ax.get_axes_locator())
26+
locator=ax.get_axes_locator()
27+
iflocatorisnotNone:
28+
ax.apply_aspect(locator(ax,None))
29+
locator_list.append(locator)
2730
current_pos=ax.get_position(original=False).frozen()
2831
ax.set_axes_locator(lambdaa,r,_pos=current_pos:_pos)
2932
# override the method that enforces the aspect ratio on the Axes

‎lib/matplotlib/tests/test_figure.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,24 @@ def test_savefig_pixel_ratio(backend):
532532
assertratio1==ratio2
533533

534534

535-
deftest_savefig_preserve_layout_engine(tmp_path):
535+
deftest_savefig_preserve_layout_engine():
536536
fig=plt.figure(layout='compressed')
537-
fig.savefig(tmp_path/'foo.png',bbox_inches='tight')
537+
fig.savefig(io.BytesIO(),bbox_inches='tight')
538538

539539
assertfig.get_layout_engine()._compress
540540

541541

542+
deftest_savefig_locate_colorbar():
543+
fig,ax=plt.subplots()
544+
pc=ax.pcolormesh(np.random.randn(2,2))
545+
cbar=fig.colorbar(pc,aspect=40)
546+
fig.savefig(io.BytesIO(),bbox_inches=mpl.transforms.Bbox([[0,0], [4,4]]))
547+
548+
# Check that an aspect ratio has been applied.
549+
assert (cbar.ax.get_position(original=True).bounds!=
550+
cbar.ax.get_position(original=False).bounds)
551+
552+
542553
deftest_figure_repr():
543554
fig=plt.figure(figsize=(10,20),dpi=10)
544555
assertrepr(fig)=="<Figure size 100x200 with 0 Axes>"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp