Skip to content

Commit 2d2dab5

Browse files
authored
Merge pull request #12643 from dstansby/fancyarrowunits
Allow unit input to FancyArrowPatch
2 parents 4e61c69 + 39ea5a4 commit 2d2dab5

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lib/matplotlib/patches.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,14 @@ def get_path(self):
572572
def get_window_extent(self, renderer=None):
573573
return self.get_path().get_extents(self.get_transform())
574574

575+
def _convert_xy_units(self, xy):
576+
"""
577+
Convert x and y units for a tuple (x, y)
578+
"""
579+
x = self.convert_xunits(xy[0])
580+
y = self.convert_yunits(xy[1])
581+
return (x, y)
582+
575583

576584
patchdoc = artist.kwdoc(Patch)
577585
for k in ('Rectangle', 'Circle', 'RegularPolygon', 'Polygon', 'Wedge', 'Arrow',
@@ -4262,8 +4270,10 @@ def get_path_in_displaycoord(self):
42624270
dpi_cor = self.get_dpi_cor()
42634271

42644272
if self._posA_posB is not None:
4265-
posA = self.get_transform().transform_point(self._posA_posB[0])
4266-
posB = self.get_transform().transform_point(self._posA_posB[1])
4273+
posA = self._convert_xy_units(self._posA_posB[0])
4274+
posB = self._convert_xy_units(self._posA_posB[1])
4275+
posA = self.get_transform().transform_point(posA)
4276+
posB = self.get_transform().transform_point(posB)
42674277
_path = self.get_connectionstyle()(posA, posB,
42684278
patchA=self.patchA,
42694279
patchB=self.patchB,

lib/matplotlib/tests/test_patches.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88
from matplotlib.cbook import MatplotlibDeprecationWarning
9-
from matplotlib.patches import Polygon, Rectangle
9+
from matplotlib.patches import Polygon, Rectangle, FancyArrowPatch
1010
from matplotlib.testing.decorators import image_comparison, check_figures_equal
1111
import matplotlib.pyplot as plt
1212
from matplotlib import (
@@ -468,3 +468,12 @@ def test_shadow(fig_test, fig_ref):
468468
alpha=.5)
469469
a2.add_patch(shadow)
470470
a2.add_patch(rect)
471+
472+
473+
def test_fancyarrow_units():
474+
from datetime import datetime
475+
# Smoke test to check that FancyArrowPatch works with units
476+
dtime = datetime(2000, 1, 1)
477+
fig, ax = plt.subplots()
478+
arrow = FancyArrowPatch((0, dtime), (0.01, dtime))
479+
ax.add_patch(arrow)

0 commit comments

Comments
 (0)