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

Skip to content

Commit 861d155

Browse files
authored
Merge pull request #21519 from anntzer/mi
mark_inset should manually unstale axes limits before drawing itself.
2 parents 17fcacc + 5c74f1d commit 861d155

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/mpl_toolkits/axes_grid1/inset_locator.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,22 @@ def zoomed_inset_axes(parent_axes, zoom, loc='upper right',
579579
return inset_axes
580580

581581

582+
class _TransformedBboxWithCallback(TransformedBbox):
583+
"""
584+
Variant of `.TransformBbox` which calls *callback* before returning points.
585+
586+
Used by `.mark_inset` to unstale the parent axes' viewlim as needed.
587+
"""
588+
589+
def __init__(self, *args, callback, **kwargs):
590+
super().__init__(*args, **kwargs)
591+
self._callback = callback
592+
593+
def get_points(self):
594+
self._callback()
595+
return super().get_points()
596+
597+
582598
@docstring.dedent_interpd
583599
def mark_inset(parent_axes, inset_axes, loc1, loc2, **kwargs):
584600
"""
@@ -613,7 +629,9 @@ def mark_inset(parent_axes, inset_axes, loc1, loc2, **kwargs):
613629
p1, p2 : `matplotlib.patches.Patch`
614630
The patches connecting two corners of the inset axes and its area.
615631
"""
616-
rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData)
632+
rect = _TransformedBboxWithCallback(
633+
inset_axes.viewLim, parent_axes.transData,
634+
callback=parent_axes._unstale_viewLim)
617635

618636
if 'fill' in kwargs:
619637
pp = BboxPatch(rect, **kwargs)

lib/mpl_toolkits/tests/test_axes_grid1.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from matplotlib.colors import LogNorm
99
from matplotlib.transforms import Bbox, TransformedBbox
1010
from matplotlib.testing.decorators import (
11-
image_comparison, remove_ticks_and_titles)
11+
check_figures_equal, image_comparison, remove_ticks_and_titles)
1212

1313
from mpl_toolkits.axes_grid1 import (
1414
axes_size as Size,
@@ -494,3 +494,19 @@ def test_grid_axes_position(direction):
494494
assert loc[1]._nx > loc[0]._nx and loc[2]._ny < loc[0]._ny
495495
assert loc[0]._nx == loc[2]._nx and loc[0]._ny == loc[1]._ny
496496
assert loc[3]._nx == loc[1]._nx and loc[3]._ny == loc[2]._ny
497+
498+
499+
@check_figures_equal(extensions=["png"])
500+
def test_mark_inset_unstales_viewlim(fig_test, fig_ref):
501+
inset, full = fig_test.subplots(1, 2)
502+
full.plot([0, 5], [0, 5])
503+
inset.set(xlim=(1, 2), ylim=(1, 2))
504+
# Check that mark_inset unstales full's viewLim before drawing the marks.
505+
mark_inset(full, inset, 1, 4)
506+
507+
inset, full = fig_ref.subplots(1, 2)
508+
full.plot([0, 5], [0, 5])
509+
inset.set(xlim=(1, 2), ylim=(1, 2))
510+
mark_inset(full, inset, 1, 4)
511+
# Manually unstale the full's viewLim.
512+
fig_ref.canvas.draw()

0 commit comments

Comments
 (0)