Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit daaf978

Browse files
authored
Merge pull request #13419 from jklymak/fix-secondary-axis-resize
FIX: secondary_axis resize
2 parents 9f0afd2 + f96eba8 commit daaf978

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

lib/matplotlib/axes/_secondary_axes.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ def _make_secondary_locator(rect, parent):
4343
*parent*.
4444
"""
4545
_rect = mtransforms.Bbox.from_bounds(*rect)
46-
bb = mtransforms.TransformedBbox(_rect, parent.transAxes)
47-
tr = parent.figure.transFigure.inverted()
48-
bb = mtransforms.TransformedBbox(bb, tr)
49-
5046
def secondary_locator(ax, renderer):
47+
# delay evaluating transform until draw time because the
48+
# parent transform may have changed (i.e. if window reesized)
49+
bb = mtransforms.TransformedBbox(_rect, parent.transAxes)
50+
tr = parent.figure.transFigure.inverted()
51+
bb = mtransforms.TransformedBbox(bb, tr)
5152
return bb
5253

5354
return secondary_locator

lib/matplotlib/tests/test_axes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6106,3 +6106,16 @@ def test_secondary_fail():
61066106
axsec = ax.secondary_xaxis('right')
61076107
with pytest.raises(ValueError):
61086108
axsec = ax.secondary_yaxis('bottom')
6109+
6110+
6111+
def test_secondary_resize():
6112+
fig, ax = plt.subplots(figsize=(10, 5))
6113+
ax.plot(np.arange(2, 11), np.arange(2, 11))
6114+
def invert(x):
6115+
with np.errstate(divide='ignore'):
6116+
return 1 / x
6117+
6118+
axsec = ax.secondary_xaxis('top', functions=(invert, invert))
6119+
fig.canvas.draw()
6120+
fig.set_size_inches((7, 4))
6121+
assert_allclose(ax.get_position().extents, [0.125, 0.1, 0.9, 0.9])

0 commit comments

Comments
 (0)