Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d1fddc7

Browse filesBrowse files
afvincentjenshnielsen
authored andcommitted
First draft to correct issue matplotlib#6035 and to write relevant unit tests. Does break old unit tests of fancyarrow (test_arrow_patches.py)!
1 parent 597d2ef commit d1fddc7
Copy full SHA for d1fddc7

File tree

Expand file treeCollapse file tree

2 files changed

+53
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+53
-1
lines changed

‎lib/matplotlib/patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/patches.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4056,18 +4056,22 @@ def __init__(self, posA=None, posB=None,
40564056

40574057
self._mutation_scale = mutation_scale
40584058
self._mutation_aspect = mutation_aspect
4059+
# Provide a ref. to scale '_mutation_scale' when setting '_dpi_cor'.
4060+
self._genuine_mutation_scale = mutation_scale
40594061

40604062
self.set_dpi_cor(dpi_cor)
40614063
#self._draw_in_display_coordinate = True
40624064

40634065
def set_dpi_cor(self, dpi_cor):
40644066
"""
40654067
dpi_cor is currently used for linewidth-related things and
4066-
shrink factor. Mutation scale is not affected by this.
4068+
shrink factor. Mutation scale *is* affected by this.
40674069
"""
40684070

40694071
self._dpi_cor = dpi_cor
40704072
self.stale = True
4073+
# Scale `_mutation_scale` properly with the new DPI (see issue #6035).
4074+
self._mutation_scale = self._genuine_mutation_scale * dpi_cor
40714075

40724076
def get_dpi_cor(self):
40734077
"""

‎lib/matplotlib/tests/test_arrow_patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_arrow_patches.py
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,54 @@ def test_boxarrow():
5252
bbox=dict(boxstyle=stylename, fc="w", ec="k"))
5353

5454

55+
def prepare_fancyarrow_for_head_size_test():
56+
"""
57+
Convenience function that prepares and return 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+
fig = plt.figure(figsize=(6, 4), dpi=50)
64+
ax = fig.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=150))
70+
return fig
71+
72+
73+
@image_comparison(baseline_images=['fancyarrow_head_size_100dpi'],
74+
remove_text=True, extensions=['svg', 'pdf', 'png'],
75+
savefig_kwarg=dict(dpi=100))
76+
def test_fancy_arrow_patch_head_size_100dpi():
77+
"""
78+
Check the export of a FancyArrowPatch @ 100 DPI. The FancyArrowPatch
79+
is instanciated through a dedicated function because another similar test
80+
checks the same export but with a different DPI value.
81+
82+
Remark: may be more explicit to create a dedicated test for SVG and PDF,
83+
as a DPI value is not very relevant here...
84+
"""
85+
86+
prepare_fancyarrow_for_head_size_test()
87+
88+
89+
@image_comparison(baseline_images=['fancyarrow_head_size_300dpi'],
90+
remove_text=True,
91+
extensions=['png'], # pdf and svg already tested @ 100 DPI
92+
savefig_kwarg=dict(dpi=300))
93+
def test_fancy_arrow_patch_head_size_300dpi():
94+
"""
95+
Check the export of a FancyArrowPatch @ 300 DPI. The FancyArrowPatch
96+
is instanciated through a dedicated function because another similar test
97+
checks the same export but with a different DPI value.
98+
"""
99+
100+
prepare_fancyarrow_for_head_size_test()
101+
102+
55103
if __name__ == '__main__':
56104
import nose
57105
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.