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

Skip to content

Commit 227180c

Browse files
committed
test 'figure points' coordinate system
1 parent 980b63e commit 227180c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/matplotlib/patches.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4596,8 +4596,8 @@ def _get_xy(self, xy, s, axes=None):
45964596

45974597
fig = self.get_figure(root=False)
45984598
if s in ["figure points", "axes points"]:
4599-
x *= fig.dpi / 72
4600-
y *= fig.dpi / 72
4599+
x = x * fig.dpi / 72
4600+
y = y * fig.dpi / 72
46014601
s = s.replace("points", "pixels")
46024602
elif s == "figure fraction":
46034603
s = fig.transFigure

lib/matplotlib/tests/test_patches.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,28 @@ def test_connection_patch_fig(fig_test, fig_ref):
606606
fig_ref.add_artist(con)
607607

608608

609+
@check_figures_equal(extensions=["png"])
610+
def test_connection_patch_pixel_points(fig_test, fig_ref):
611+
xyA_pts = (.3, .2)
612+
xyB_pts = (-30, -20)
613+
614+
ax1, ax2 = fig_test.subplots(1, 2)
615+
con = mpatches.ConnectionPatch(xyA=xyA_pts, coordsA="axes points", axesA=ax1,
616+
xyB=xyB_pts, coordsB="figure points",
617+
arrowstyle="->", shrinkB=5)
618+
fig_test.add_artist(con)
619+
620+
plt.rcParams["savefig.dpi"] = plt.rcParams["figure.dpi"]
621+
622+
ax1, ax2 = fig_ref.subplots(1, 2)
623+
xyA_pix = (xyA_pts[0]*(fig_ref.dpi/72), xyA_pts[1]*(fig_ref.dpi/72))
624+
xyB_pix = (xyB_pts[0]*(fig_ref.dpi/72), xyB_pts[1]*(fig_ref.dpi/72))
625+
con = mpatches.ConnectionPatch(xyA=xyA_pix, coordsA="axes pixels", axesA=ax1,
626+
xyB=xyB_pix, coordsB="figure pixels",
627+
arrowstyle="->", shrinkB=5)
628+
fig_ref.add_artist(con)
629+
630+
609631
def test_datetime_rectangle():
610632
# Check that creating a rectangle with timedeltas doesn't fail
611633
from datetime import datetime, timedelta

0 commit comments

Comments
 (0)