Skip to content

Commit 39ea5a4

Browse files
committed
Allow unit input to FancyArrowPatch
1 parent 6c0aa84 commit 39ea5a4

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
@@ -571,6 +571,14 @@ def get_path(self):
571571
def get_window_extent(self, renderer=None):
572572
return self.get_path().get_extents(self.get_transform())
573573

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

575583
patchdoc = artist.kwdoc(Patch)
576584
for k in ('Rectangle', 'Circle', 'RegularPolygon', 'Polygon', 'Wedge', 'Arrow',
@@ -4253,8 +4261,10 @@ def get_path_in_displaycoord(self):
42534261
dpi_cor = self.get_dpi_cor()
42544262

42554263
if self._posA_posB is not None:
4256-
posA = self.get_transform().transform_point(self._posA_posB[0])
4257-
posB = self.get_transform().transform_point(self._posA_posB[1])
4264+
posA = self._convert_xy_units(self._posA_posB[0])
4265+
posB = self._convert_xy_units(self._posA_posB[1])
4266+
posA = self.get_transform().transform_point(posA)
4267+
posB = self.get_transform().transform_point(posB)
42584268
_path = self.get_connectionstyle()(posA, posB,
42594269
patchA=self.patchA,
42604270
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)