Skip to content

Allow unit input to FancyArrowPatch #12643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,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 @@ -4253,8 +4261,10 @@ def get_path_in_displaycoord(self):
dpi_cor = self.get_dpi_cor()

if self._posA_posB is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems good - is it worth looking at the other patches to see if we need to add this? You could test with the same test as below and see if they fail?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have the bandwidth to do this at the moment; perhaps quite a nice thing to add as a new-contributor friendly issue though.

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)