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

Skip to content

Commit b6154b6

Browse files
authored
Merge pull request matplotlib#11753 from jklymak/fix-apply-aspect-before-draw
FIX: Apply aspect before drawing starts
2 parents 2e65e40 + a4e7ddd commit b6154b6

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,23 @@ def draw(self, renderer):
16301630
if not artist.get_animated()),
16311631
key=lambda artist: artist.get_zorder())
16321632

1633+
for ax in self.axes:
1634+
locator = ax.get_axes_locator()
1635+
if locator:
1636+
pos = locator(ax, renderer)
1637+
ax.apply_aspect(pos)
1638+
else:
1639+
ax.apply_aspect()
1640+
1641+
for child in ax.get_children():
1642+
if hasattr(child, 'apply_aspect'):
1643+
locator = child.get_axes_locator()
1644+
if locator:
1645+
pos = locator(child, renderer)
1646+
child.apply_aspect(pos)
1647+
else:
1648+
child.apply_aspect()
1649+
16331650
try:
16341651
renderer.open_group('figure')
16351652
if self.get_constrained_layout() and self.axes:

lib/matplotlib/tests/test_axes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5931,3 +5931,20 @@ def test_scatter_empty_data():
59315931
# making sure this does not raise an exception
59325932
plt.scatter([], [])
59335933
plt.scatter([], [], s=[], c=[])
5934+
5935+
5936+
@image_comparison(baseline_images=['annotate_across_transforms'],
5937+
style='mpl20', extensions=['png'], remove_text=True)
5938+
def test_annotate_across_transforms():
5939+
x = np.linspace(0, 10, 200)
5940+
y = np.exp(-x) * np.sin(x)
5941+
5942+
fig, ax = plt.subplots(figsize=(3.39, 3))
5943+
ax.plot(x, y)
5944+
axins = ax.inset_axes([0.4, 0.5, 0.3, 0.3])
5945+
axins.set_aspect(0.2)
5946+
axins.xaxis.set_visible(False)
5947+
axins.yaxis.set_visible(False)
5948+
ax.annotate("", xy=(x[150], y[150]), xycoords=ax.transData,
5949+
xytext=(1, 0), textcoords=axins.transAxes,
5950+
arrowprops=dict(arrowstyle="->"))

0 commit comments

Comments
 (0)