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

Skip to content

Commit 20b46db

Browse files
afvincentjenshnielsen
authored andcommitted
Add a new unit test to check that a raw FancyArrowPatch is DPI-independent.
1 parent f0eda1f commit 20b46db

File tree

3 files changed

+28
-31
lines changed

3 files changed

+28
-31
lines changed

lib/matplotlib/tests/test_arrow_patches.py

Lines changed: 28 additions & 31 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 # adopting scipy import conventions
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,52 +52,49 @@ def test_boxarrow():
5252
bbox=dict(boxstyle=stylename, fc="w", ec="k"))
5353

5454

55-
def prepare_fancyarrow_for_head_size_test():
55+
def prepare_fancyarrow_dpi_cor_test():
5656
"""
5757
Convenience function that prepares and return a FancyArrowPatch. It aims
5858
at being used to test that the size of the arrow head does not depend on
59-
the DPI value of the exported picture.
59+
the DPI value of the exported picture.
6060
6161
NB: this function *is not* a test in itself!
6262
"""
63-
fig = plt.figure(figsize=(6, 4), dpi=50)
64-
ax = fig.add_subplot(111)
63+
fig2 = plt.figure("fancyarrow_dpi_cor_test", figsize=(4, 3), dpi=50)
64+
ax = fig2.add_subplot(111)
6565
ax.set_xlim([0, 1])
6666
ax.set_ylim([0, 1])
6767
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
68+
lw=3, arrowstyle=u'->',
69+
mutation_scale=100))
70+
return fig2
7171

7272

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():
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():
7777
"""
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.
78+
Check the export of a FancyArrowPatch @ 100 DPI. FancyArrowPatch is
79+
instanciated through a dedicated function because another similar test
80+
checks a similar export but with a different DPI value.
8181
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...
82+
Remark: test only a rasterized format.
8483
"""
85-
86-
prepare_fancyarrow_for_head_size_test()
8784

85+
prepare_fancyarrow_dpi_cor_test()
8886

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():
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():
9492
"""
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.
93+
As test_fancyarrow_dpi_cor_100dpi, but exports @ 200 DPI. The relative size
94+
of the arrow head should be the same.
9895
"""
99-
100-
prepare_fancyarrow_for_head_size_test()
96+
97+
prepare_fancyarrow_dpi_cor_test()
10198

10299

103100
if __name__ == '__main__':

0 commit comments

Comments
 (0)