Skip to content

FIX: secondary_axis resize #13419

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions lib/matplotlib/axes/_secondary_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ def _make_secondary_locator(rect, parent):
*parent*.
"""
_rect = mtransforms.Bbox.from_bounds(*rect)
bb = mtransforms.TransformedBbox(_rect, parent.transAxes)
tr = parent.figure.transFigure.inverted()
bb = mtransforms.TransformedBbox(bb, tr)

def secondary_locator(ax, renderer):
# delay evaluating transform until draw time because the
# parent transform may have changed (i.e. if window reesized)
bb = mtransforms.TransformedBbox(_rect, parent.transAxes)
Copy link
Member Author

Choose a reason for hiding this comment

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

@anntzer I knew there was a reason for this song and dance...

Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a comment mentioning this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. Comment added.

tr = parent.figure.transFigure.inverted()
bb = mtransforms.TransformedBbox(bb, tr)
return bb

return secondary_locator
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6106,3 +6106,16 @@ def test_secondary_fail():
axsec = ax.secondary_xaxis('right')
with pytest.raises(ValueError):
axsec = ax.secondary_yaxis('bottom')


def test_secondary_resize():
fig, ax = plt.subplots(figsize=(10, 5))
ax.plot(np.arange(2, 11), np.arange(2, 11))
def invert(x):
with np.errstate(divide='ignore'):
return 1 / x

axsec = ax.secondary_xaxis('top', functions=(invert, invert))
fig.canvas.draw()
fig.set_size_inches((7, 4))
assert_allclose(ax.get_position().extents, [0.125, 0.1, 0.9, 0.9])