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

Skip to content

Commit 8e65fee

Browse files
anntzerMeeseeksDev[bot]
authored andcommitted
Backport PR #15020: Let connectionpatch be drawn on figure level
1 parent 4622afd commit 8e65fee

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

lib/matplotlib/patches.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4592,7 +4592,11 @@ def _check_xy(self, renderer):
45924592
if b or (b is None and self.coords1 == "data"):
45934593
x, y = self.xy1
45944594
xy_pixel = self._get_xy(x, y, self.coords1, self.axesA)
4595-
if not self.axes.contains_point(xy_pixel):
4595+
if self.axesA is None:
4596+
axes = self.axes
4597+
else:
4598+
axes = self.axesA
4599+
if not axes.contains_point(xy_pixel):
45964600
return False
45974601

45984602
if b or (b is None and self.coords2 == "data"):

lib/matplotlib/tests/test_patches.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,18 @@ def test_connection_patch():
402402
ax2.add_artist(con)
403403

404404

405+
def test_connection_patch_fig():
406+
# Test that connection patch can be added as figure artist
407+
fig, (ax1, ax2) = plt.subplots(1, 2)
408+
xy = (0.3, 0.2)
409+
con = mpatches.ConnectionPatch(xyA=xy, xyB=xy,
410+
coordsA="data", coordsB="data",
411+
axesA=ax1, axesB=ax2,
412+
arrowstyle="->", shrinkB=5)
413+
fig.add_artist(con)
414+
fig.canvas.draw()
415+
416+
405417
def test_datetime_rectangle():
406418
# Check that creating a rectangle with timedeltas doesn't fail
407419
from datetime import datetime, timedelta

0 commit comments

Comments
 (0)