Skip to content

Commit

Permalink
Merge pull request matplotlib#12643 from dstansby/fancyarrowunits
Browse files Browse the repository at this point in the history
Allow unit input to FancyArrowPatch
  • Loading branch information
dopplershift authored Nov 10, 2018
2 parents 4e61c69 + 39ea5a4 commit 2d2dab5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 12 additions & 2 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,14 @@ def get_path(self):
def get_window_extent(self, renderer=None):
return self.get_path().get_extents(self.get_transform())

def _convert_xy_units(self, xy):
"""
Convert x and y units for a tuple (x, y)
"""
x = self.convert_xunits(xy[0])
y = self.convert_yunits(xy[1])
return (x, y)


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

if self._posA_posB is not None:
posA = self.get_transform().transform_point(self._posA_posB[0])
posB = self.get_transform().transform_point(self._posA_posB[1])
posA = self._convert_xy_units(self._posA_posB[0])
posB = self._convert_xy_units(self._posA_posB[1])
posA = self.get_transform().transform_point(posA)
posB = self.get_transform().transform_point(posB)
_path = self.get_connectionstyle()(posA, posB,
patchA=self.patchA,
patchB=self.patchB,
Expand Down
11 changes: 10 additions & 1 deletion lib/matplotlib/tests/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

from matplotlib.cbook import MatplotlibDeprecationWarning
from matplotlib.patches import Polygon, Rectangle
from matplotlib.patches import Polygon, Rectangle, FancyArrowPatch
from matplotlib.testing.decorators import image_comparison, check_figures_equal
import matplotlib.pyplot as plt
from matplotlib import (
Expand Down Expand Up @@ -468,3 +468,12 @@ def test_shadow(fig_test, fig_ref):
alpha=.5)
a2.add_patch(shadow)
a2.add_patch(rect)


def test_fancyarrow_units():
from datetime import datetime
# Smoke test to check that FancyArrowPatch works with units
dtime = datetime(2000, 1, 1)
fig, ax = plt.subplots()
arrow = FancyArrowPatch((0, dtime), (0.01, dtime))
ax.add_patch(arrow)

0 comments on commit 2d2dab5

Please sign in to comment.