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

FIX constrained_layout w/ hidden axes#14919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
anntzer merged 2 commits intomatplotlib:masterfromjklymak:fix-CL-hidden-axes
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletionlib/matplotlib/_constrained_layout.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -272,7 +272,11 @@ def _make_layout_margins(ax, renderer, h_pad, w_pad):
invTransFig = fig.transFigure.inverted().transform_bbox
pos = ax.get_position(original=True)
tightbbox = ax.get_tightbbox(renderer=renderer)
bbox = invTransFig(tightbbox)
if tightbbox is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Just:

bbox = pos if tightbbox is None else invTransFig(tightbbox)

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I find those really hard to read a lot of the time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Actually, when reading a function for a basic understanding what it does I find this more easy.

It's just one line saying: "Setsbbox depending on some condition". The if/else is already more low level.

But not fighting over this.

bbox = pos
else:
bbox = invTransFig(tightbbox)

# this can go wrong:
if not (np.isfinite(bbox.width) and np.isfinite(bbox.height)):
# just abort, this is likely a bad set of co-ordinates that
Expand Down
13 changes: 13 additions & 0 deletionslib/matplotlib/tests/test_constrainedlayout.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -387,3 +387,16 @@ def test_colorbar_location():
fig.colorbar(pcm, ax=axs[-2, 3:], shrink=0.5, location='top')
fig.colorbar(pcm, ax=axs[0, 0], shrink=0.5, location='left')
fig.colorbar(pcm, ax=axs[1:3, 2], shrink=0.5, location='right')


def test_hidden_axes():
# test that if we make an axes not visible that constrained_layout
# still works. Note the axes still takes space in the layout
# (as does a gridspec slot that is empty)
fig, axs = plt.subplots(2, 2, constrained_layout=True)
axs[0, 1].set_visible(False)
fig.canvas.draw()
extents1 = np.copy(axs[0, 0].get_position().extents)

np.testing.assert_allclose(extents1,
[0.045552, 0.548288, 0.47319, 0.982638], rtol=1e-5)

[8]ページ先頭

©2009-2025 Movatter.jp