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

Appearance settings

Commit daaf978

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

File tree

Expand file treeCollapse file tree

2 files changed

+18
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-4
lines changed

‎lib/matplotlib/axes/_secondary_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_secondary_axes.py
+5-4Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+13Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.