Skip to content

Patch issue 6035 rebase #6504

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 12 commits into from
May 30, 2016
32 changes: 17 additions & 15 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -4063,7 +4063,7 @@ def __init__(self, posA=None, posB=None,
def set_dpi_cor(self, dpi_cor):
"""
dpi_cor is currently used for linewidth-related things and
shrink factor. Mutation scale is not affected by this.
shrink factor. Mutation scale is affected by this.
"""

self._dpi_cor = dpi_cor
Expand All @@ -4072,7 +4072,7 @@ def set_dpi_cor(self, dpi_cor):
def get_dpi_cor(self):
"""
dpi_cor is currently used for linewidth-related things and
shrink factor. Mutation scale is not affected by this.
shrink factor. Mutation scale is affected by this.
"""

return self._dpi_cor
Expand Down Expand Up @@ -4224,15 +4224,16 @@ def get_path_in_displaycoord(self):
patchB=self.patchB,
shrinkA=self.shrinkA * dpi_cor,
shrinkB=self.shrinkB * dpi_cor
)
)
else:
_path = self.get_transform().transform_path(self._path_original)

_path, fillable = self.get_arrowstyle()(_path,
self.get_mutation_scale(),
self.get_linewidth() * dpi_cor,
self.get_mutation_aspect()
)
_path, fillable = self.get_arrowstyle()(
_path,
self.get_mutation_scale() * dpi_cor,
self.get_linewidth() * dpi_cor,
self.get_mutation_aspect()
)

#if not fillable:
# self._fill = False
Expand Down Expand Up @@ -4542,13 +4543,14 @@ def get_path_in_displaycoord(self):
patchB=self.patchB,
shrinkA=self.shrinkA * dpi_cor,
shrinkB=self.shrinkB * dpi_cor
)

_path, fillable = self.get_arrowstyle()(_path,
self.get_mutation_scale(),
self.get_linewidth() * dpi_cor,
self.get_mutation_aspect()
)
)

_path, fillable = self.get_arrowstyle()(
_path,
self.get_mutation_scale() * dpi_cor,
self.get_linewidth() * dpi_cor,
self.get_mutation_aspect()
)

return _path, fillable

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/polar_axes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/polar_coords.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 48 additions & 3 deletions lib/matplotlib/tests/test_arrow_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import matplotlib.pyplot as plt
from matplotlib.testing.decorators import image_comparison
import matplotlib
import matplotlib.patches as mpatches


def draw_arrow(ax, t, r):
Expand All @@ -18,7 +18,7 @@ def draw_arrow(ax, t, r):
def test_fancyarrow():
# Added 0 to test division by zero error described in issue 3930
r = [0.4, 0.3, 0.2, 0.1, 0]
t = ["fancy", "simple", matplotlib.patches.ArrowStyle.Fancy()]
t = ["fancy", "simple", mpatches.ArrowStyle.Fancy()]

fig, axes = plt.subplots(len(t), len(r), squeeze=False,
subplot_kw=dict(aspect=True),
Expand All @@ -34,7 +34,7 @@ def test_fancyarrow():
@image_comparison(baseline_images=['boxarrow_test_image'], extensions=['png'])
def test_boxarrow():

styles = matplotlib.patches.BoxStyle.get_styles()
styles = mpatches.BoxStyle.get_styles()

n = len(styles)
spacing = 1.2
Expand All @@ -52,6 +52,51 @@ def test_boxarrow():
bbox=dict(boxstyle=stylename, fc="w", ec="k"))


def __prepare_fancyarrow_dpi_cor_test():
"""
Convenience function that prepares and returns a FancyArrowPatch. It aims
at being used to test that the size of the arrow head does not depend on
the DPI value of the exported picture.

NB: this function *is not* a test in itself!
"""
fig2 = plt.figure("fancyarrow_dpi_cor_test", figsize=(4, 3), dpi=50)
ax = fig2.add_subplot(111)
ax.set_xlim([0, 1])
ax.set_ylim([0, 1])
ax.add_patch(mpatches.FancyArrowPatch(posA=(0.3, 0.4), posB=(0.8, 0.6),
lw=3, arrowstyle=u'->',
mutation_scale=100))
return fig2


@image_comparison(baseline_images=['fancyarrow_dpi_cor_100dpi'],
remove_text=True, extensions=['png'],
savefig_kwarg=dict(dpi=100))
def test_fancyarrow_dpi_cor_100dpi():
"""
Check the export of a FancyArrowPatch @ 100 DPI. FancyArrowPatch is
instantiated through a dedicated function because another similar test
checks a similar export but with a different DPI value.

Remark: test only a rasterized format.
"""

__prepare_fancyarrow_dpi_cor_test()


@image_comparison(baseline_images=['fancyarrow_dpi_cor_200dpi'],
remove_text=True, extensions=['png'],
savefig_kwarg=dict(dpi=200))
def test_fancyarrow_dpi_cor_200dpi():
"""
As test_fancyarrow_dpi_cor_100dpi, but exports @ 200 DPI. The relative size
of the arrow head should be the same.
"""

__prepare_fancyarrow_dpi_cor_test()


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
10 changes: 4 additions & 6 deletions lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2147,7 +2147,6 @@ def _update_position_xytext(self, renderer, xy_pixel):

d = self.arrowprops.copy()
ms = d.pop("mutation_scale", self.get_size())
ms = renderer.points_to_pixels(ms)
self.arrow_patch.set_mutation_scale(ms)

if "arrowstyle" not in d:
Expand All @@ -2164,11 +2163,10 @@ def _update_position_xytext(self, renderer, xy_pixel):
" use 'headlength' to set the head length in points.")
headlength = d.pop('headlength', 12)

to_style = self.figure.dpi / (72 * ms)

stylekw = dict(head_length=headlength * to_style,
head_width=headwidth * to_style,
tail_width=width * to_style)
# NB: ms is in pts
stylekw = dict(head_length=headlength / ms,
head_width=headwidth / ms,
tail_width=width / ms)

self.arrow_patch.set_arrowstyle('simple', **stylekw)

Expand Down