Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72653f2

Browse files
committed
Merge pull request #6504 from jenshnielsen/patch-issue-6035-rebase
FIX: dpi dependent arrow heads Conflicts: lib/matplotlib/tests/baseline_images/test_transforms/pre_transform_data.png Keep version form cherry-pick Manually backport part of bd63121 which renamed the test files.
1 parent ff98856 commit 72653f2

16 files changed

+869
-824
lines changed

lib/matplotlib/patches.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4063,7 +4063,7 @@ def __init__(self, posA=None, posB=None,
40634063
def set_dpi_cor(self, dpi_cor):
40644064
"""
40654065
dpi_cor is currently used for linewidth-related things and
4066-
shrink factor. Mutation scale is not affected by this.
4066+
shrink factor. Mutation scale is affected by this.
40674067
"""
40684068

40694069
self._dpi_cor = dpi_cor
@@ -4072,7 +4072,7 @@ def set_dpi_cor(self, dpi_cor):
40724072
def get_dpi_cor(self):
40734073
"""
40744074
dpi_cor is currently used for linewidth-related things and
4075-
shrink factor. Mutation scale is not affected by this.
4075+
shrink factor. Mutation scale is affected by this.
40764076
"""
40774077

40784078
return self._dpi_cor
@@ -4224,15 +4224,16 @@ def get_path_in_displaycoord(self):
42244224
patchB=self.patchB,
42254225
shrinkA=self.shrinkA * dpi_cor,
42264226
shrinkB=self.shrinkB * dpi_cor
4227-
)
4227+
)
42284228
else:
42294229
_path = self.get_transform().transform_path(self._path_original)
42304230

4231-
_path, fillable = self.get_arrowstyle()(_path,
4232-
self.get_mutation_scale(),
4233-
self.get_linewidth() * dpi_cor,
4234-
self.get_mutation_aspect()
4235-
)
4231+
_path, fillable = self.get_arrowstyle()(
4232+
_path,
4233+
self.get_mutation_scale() * dpi_cor,
4234+
self.get_linewidth() * dpi_cor,
4235+
self.get_mutation_aspect()
4236+
)
42364237

42374238
#if not fillable:
42384239
# self._fill = False
@@ -4542,13 +4543,14 @@ def get_path_in_displaycoord(self):
45424543
patchB=self.patchB,
45434544
shrinkA=self.shrinkA * dpi_cor,
45444545
shrinkB=self.shrinkB * dpi_cor
4545-
)
4546-
4547-
_path, fillable = self.get_arrowstyle()(_path,
4548-
self.get_mutation_scale(),
4549-
self.get_linewidth() * dpi_cor,
4550-
self.get_mutation_aspect()
4551-
)
4546+
)
4547+
4548+
_path, fillable = self.get_arrowstyle()(
4549+
_path,
4550+
self.get_mutation_scale() * dpi_cor,
4551+
self.get_linewidth() * dpi_cor,
4552+
self.get_mutation_aspect()
4553+
)
45524554

45534555
return _path, fillable
45544556

lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_colormap_test_image.svg renamed to lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_colormap.svg

Lines changed: 799 additions & 799 deletions
Loading

lib/matplotlib/tests/test_arrow_patches.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import matplotlib.pyplot as plt
77
from matplotlib.testing.decorators import image_comparison
8-
import matplotlib
8+
import matplotlib.patches as mpatches
99

1010

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

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

37-
styles = matplotlib.patches.BoxStyle.get_styles()
37+
styles = mpatches.BoxStyle.get_styles()
3838

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

5454

55+
def __prepare_fancyarrow_dpi_cor_test():
56+
"""
57+
Convenience function that prepares and returns a FancyArrowPatch. It aims
58+
at being used to test that the size of the arrow head does not depend on
59+
the DPI value of the exported picture.
60+
61+
NB: this function *is not* a test in itself!
62+
"""
63+
fig2 = plt.figure("fancyarrow_dpi_cor_test", figsize=(4, 3), dpi=50)
64+
ax = fig2.add_subplot(111)
65+
ax.set_xlim([0, 1])
66+
ax.set_ylim([0, 1])
67+
ax.add_patch(mpatches.FancyArrowPatch(posA=(0.3, 0.4), posB=(0.8, 0.6),
68+
lw=3, arrowstyle=u'->',
69+
mutation_scale=100))
70+
return fig2
71+
72+
73+
@image_comparison(baseline_images=['fancyarrow_dpi_cor_100dpi'],
74+
remove_text=True, extensions=['png'],
75+
savefig_kwarg=dict(dpi=100))
76+
def test_fancyarrow_dpi_cor_100dpi():
77+
"""
78+
Check the export of a FancyArrowPatch @ 100 DPI. FancyArrowPatch is
79+
instantiated through a dedicated function because another similar test
80+
checks a similar export but with a different DPI value.
81+
82+
Remark: test only a rasterized format.
83+
"""
84+
85+
__prepare_fancyarrow_dpi_cor_test()
86+
87+
88+
@image_comparison(baseline_images=['fancyarrow_dpi_cor_200dpi'],
89+
remove_text=True, extensions=['png'],
90+
savefig_kwarg=dict(dpi=200))
91+
def test_fancyarrow_dpi_cor_200dpi():
92+
"""
93+
As test_fancyarrow_dpi_cor_100dpi, but exports @ 200 DPI. The relative size
94+
of the arrow head should be the same.
95+
"""
96+
97+
__prepare_fancyarrow_dpi_cor_test()
98+
99+
55100
if __name__ == '__main__':
56101
import nose
57102
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_streamplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def velocity_field():
1717
return X, Y, U, V
1818

1919

20-
@image_comparison(baseline_images=['streamplot_colormap_test_image'])
20+
@image_comparison(baseline_images=['streamplot_colormap'])
2121
def test_colormap():
2222
X, Y, U, V = velocity_field()
2323
plt.streamplot(X, Y, U, V, color=U, density=0.6, linewidth=2,

lib/matplotlib/text.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,6 @@ def _update_position_xytext(self, renderer, xy_pixel):
21472147

21482148
d = self.arrowprops.copy()
21492149
ms = d.pop("mutation_scale", self.get_size())
2150-
ms = renderer.points_to_pixels(ms)
21512150
self.arrow_patch.set_mutation_scale(ms)
21522151

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

2167-
to_style = self.figure.dpi / (72 * ms)
2168-
2169-
stylekw = dict(head_length=headlength * to_style,
2170-
head_width=headwidth * to_style,
2171-
tail_width=width * to_style)
2166+
# NB: ms is in pts
2167+
stylekw = dict(head_length=headlength / ms,
2168+
head_width=headwidth / ms,
2169+
tail_width=width / ms)
21722170

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

0 commit comments

Comments
 (0)