Skip to content

Commit c8e7643

Browse files
committed
indicate_inset transform support
1 parent 84464dd commit c8e7643

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def indicate_inset(self, bounds=None, inset_ax=None, *, transform=None,
440440
441441
transform : `.Transform`
442442
Transform for the rectangle coordinates. Defaults to
443-
``ax.transAxes``, i.e. the units of *rect* are in Axes-relative
443+
``ax.transData``, i.e. the units of *rect* are in the Axes' data
444444
coordinates.
445445
446446
facecolor : :mpltype:`color`, default: 'none'

lib/matplotlib/inset.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def __init__(self, bounds=None, inset_ax=None, zorder=None, **kwargs):
5959
x, y, width, height = bounds
6060

6161
self._rectangle = Rectangle((x, y), width, height, clip_on=False, **kwargs)
62+
self._rect_trans = kwargs['transform']
6263

6364
# Connector positions cannot be calculated till the artist has been added
6465
# to an axes, so just make an empty list for now.
@@ -152,6 +153,10 @@ def _update_connectors(self):
152153
width = self._rectangle.get_width()
153154
height = self._rectangle.get_height()
154155

156+
if hasattr(self._rect_trans, '_as_mpl_transform'):
157+
self._rect_trans = self._rect_trans._as_mpl_transform(self.axes)
158+
self.rectangle.axes = self.axes
159+
155160
existing_connectors = self._connectors or [None] * 4
156161

157162
# connect the inset_axes to the rectangle
@@ -171,7 +176,7 @@ def _update_connectors(self):
171176
# parent artist.
172177
p = ConnectionPatch(
173178
xyA=xy_inset_ax, coordsA=self._inset_ax.transAxes,
174-
xyB=xy_data, coordsB=self.axes.transData,
179+
xyB=xy_data, coordsB=self._rect_trans,
175180
arrowstyle="-",
176181
edgecolor=self._edgecolor, alpha=self.get_alpha(),
177182
linestyle=self._linestyle, linewidth=self._linewidth)
@@ -182,7 +187,7 @@ def _update_connectors(self):
182187
existing.xy1 = xy_inset_ax
183188
existing.xy2 = xy_data
184189
existing.coords1 = self._inset_ax.transAxes
185-
existing.coords2 = self.axes.transData
190+
existing.coords2 = self._rect_trans
186191

187192
if existing is None:
188193
# decide which two of the lines to keep visible....

lib/matplotlib/tests/test_inset.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import matplotlib.colors as mcolors
66
import matplotlib.pyplot as plt
7+
import matplotlib.transforms as mtransforms
78
from matplotlib.testing.decorators import image_comparison, check_figures_equal
89

910

@@ -104,3 +105,33 @@ def test_zoom_inset_connector_styles():
104105
# Make one visible connector a different style
105106
indicator.connectors[1].set_linestyle('dashed')
106107
indicator.connectors[1].set_color('blue')
108+
109+
110+
@image_comparison(['zoom_inset_transform.png'], remove_text=True, style='mpl20')
111+
def test_zoom_inset_transform():
112+
fig, ax = plt.subplots()
113+
114+
ax_ins = ax.inset_axes([0.2, 0.2, 0.3, 0.15])
115+
ax_ins.set_ylim([0.3, 0.6])
116+
ax_ins.set_xlim([0.5, 0.9])
117+
118+
tr = mtransforms.Affine2D().rotate_deg(30)
119+
indicator = ax.indicate_inset_zoom(ax_ins, transform=tr + ax.transData)
120+
for conn in indicator.connectors:
121+
conn.set_visible(True)
122+
123+
124+
def test_zoom_inset_external_transform():
125+
# Smoke test that an external transform that requires an axes (i.e.
126+
# Cartopy) will work.
127+
class FussyDataTr:
128+
def _as_mpl_transform(self, axes=None):
129+
if axes is None:
130+
raise ValueError("I am a fussy transform that requires an axes")
131+
return axes.transData
132+
133+
fig, ax = plt.subplots()
134+
ax_ins = ax.inset_axes([0.2, 0.2, 0.3, 0.15])
135+
ax.indicate_inset_zoom(ax_ins, transform=FussyDataTr())
136+
137+
fig.draw_without_rendering()

0 commit comments

Comments
 (0)
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