diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index c86672c95dc9..6b61237ae1e0 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -1630,6 +1630,23 @@ def draw(self, renderer): if not artist.get_animated()), key=lambda artist: artist.get_zorder()) + for ax in self.axes: + locator = ax.get_axes_locator() + if locator: + pos = locator(ax, renderer) + ax.apply_aspect(pos) + else: + ax.apply_aspect() + + for child in ax.get_children(): + if hasattr(child, 'apply_aspect'): + locator = child.get_axes_locator() + if locator: + pos = locator(child, renderer) + child.apply_aspect(pos) + else: + child.apply_aspect() + try: renderer.open_group('figure') if self.get_constrained_layout() and self.axes: diff --git a/lib/matplotlib/tests/baseline_images/test_axes/annotate_across_transforms.png b/lib/matplotlib/tests/baseline_images/test_axes/annotate_across_transforms.png new file mode 100644 index 000000000000..d62245605fc9 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/annotate_across_transforms.png differ diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 1b56c74ee3e7..5bc1b54bbf8e 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5931,3 +5931,20 @@ def test_scatter_empty_data(): # making sure this does not raise an exception plt.scatter([], []) plt.scatter([], [], s=[], c=[]) + + +@image_comparison(baseline_images=['annotate_across_transforms'], + style='mpl20', extensions=['png'], remove_text=True) +def test_annotate_across_transforms(): + x = np.linspace(0, 10, 200) + y = np.exp(-x) * np.sin(x) + + fig, ax = plt.subplots(figsize=(3.39, 3)) + ax.plot(x, y) + axins = ax.inset_axes([0.4, 0.5, 0.3, 0.3]) + axins.set_aspect(0.2) + axins.xaxis.set_visible(False) + axins.yaxis.set_visible(False) + ax.annotate("", xy=(x[150], y[150]), xycoords=ax.transData, + xytext=(1, 0), textcoords=axins.transAxes, + arrowprops=dict(arrowstyle="->"))