Skip to content

FIX: update spine positions before get extents #11754

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
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
8 changes: 0 additions & 8 deletions lib/matplotlib/_constrained_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions lib/matplotlib/spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)