diff --git a/lib/matplotlib/_constrained_layout.py b/lib/matplotlib/_constrained_layout.py index f949fc1beadf..7f740b9980a5 100644 --- a/lib/matplotlib/_constrained_layout.py +++ b/lib/matplotlib/_constrained_layout.py @@ -145,14 +145,6 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad, ''' - try: - if fig.canvas.toolbar._active in ('PAN', 'ZOOM'): - # don't do constrained layout during zoom and pan. - return - except AttributeError: - # not toolbar, or no _active attribute.. - pass - invTransFig = fig.transFigure.inverted().transform_bbox # list of unique gridspecs that contain child axes: diff --git a/lib/matplotlib/spines.py b/lib/matplotlib/spines.py index 5747c40bba69..677dd4edc48d 100644 --- a/lib/matplotlib/spines.py +++ b/lib/matplotlib/spines.py @@ -146,6 +146,12 @@ def get_patch_transform(self): else: return super().get_patch_transform() + def get_window_extent(self, renderer=None): + # make sure the location is updated so that transforms etc are + # correct: + self._adjust_location() + return super().get_window_extent(renderer=renderer) + def get_path(self): return self._path diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 7e7f6a1bd25f..ded1f231c5b0 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5782,3 +5782,13 @@ def test_zoom_inset(): [0.8425, 0.907692]]) np.testing.assert_allclose(axin1.get_position().get_points(), xx, rtol=1e-4) + + +def test_spines_properbbox_after_zoom(): + fig, ax = plt.subplots() + bb = ax.spines['bottom'].get_window_extent(fig.canvas.get_renderer()) + # this is what zoom calls: + ax._set_view_from_bbox((320, 320, 500, 500), 'in', + None, False, False) + bb2 = ax.spines['bottom'].get_window_extent(fig.canvas.get_renderer()) + np.testing.assert_allclose(bb.get_points(), bb2.get_points(), rtol=1e-6)