From 5cd9676d88542dedc51c21f3c73f51a9015e0557 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Mon, 11 Feb 2019 19:26:00 -0800 Subject: [PATCH 1/2] FIX: secondary_axis resize --- lib/matplotlib/axes/_secondary_axes.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes/_secondary_axes.py b/lib/matplotlib/axes/_secondary_axes.py index 3cbe8e0f1ff1..b5b4598439c6 100644 --- a/lib/matplotlib/axes/_secondary_axes.py +++ b/lib/matplotlib/axes/_secondary_axes.py @@ -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) + tr = parent.figure.transFigure.inverted() + bb = mtransforms.TransformedBbox(bb, tr) return bb return secondary_locator From f96eba884ffcbb25b46b3a3919b7ab499c5139df Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Mon, 11 Feb 2019 22:11:36 -0800 Subject: [PATCH 2/2] TST: secondary_axes resize --- lib/matplotlib/tests/test_axes.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 1a848692907e..7ef48bbd2ee2 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -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]) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy