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

Skip to content

Commit a8c53ae

Browse files
committed
Add tests for the simplification/clipping infrastructure.
svn path=/trunk/matplotlib/; revision=7787
1 parent f49deee commit a8c53ae

9 files changed

Lines changed: 113 additions & 74 deletions

File tree

examples/pylab_examples/simplification_clipping_test.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

examples/tests/backend_driver.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@
181181
'shared_axis_across_figures.py',
182182
'shared_axis_demo.py',
183183
'simple_plot.py',
184-
'simplification_clipping_test.py',
185184
'specgram_demo.py',
186185
'spine_placement_demo.py',
187186
'spy_demos.py',

lib/matplotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ def tk_window_focus():
886886
'matplotlib.tests.test_dates',
887887
'matplotlib.tests.test_spines',
888888
'matplotlib.tests.test_image',
889+
'matplotlib.tests.test_simplification',
889890
]
890891

891892
def test(verbosity=0):

lib/matplotlib/testing/compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def compare_images( expected, actual, tol, in_decorator=False ):
8080
8181
# img1 = "./baseline/plot.png"
8282
# img2 = "./output/plot.png"
83-
#
83+
#
8484
# compare_images( img1, img2, 0.001 ):
8585
8686
= INPUT VARIABLES
8.72 KB
Loading
9.63 KB
Loading
6.34 KB
Loading
27.3 KB
Loading
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import numpy as np
2+
import matplotlib
3+
from matplotlib.testing.decorators import image_comparison, knownfailureif
4+
import matplotlib.pyplot as plt
5+
from matplotlib import patches, path
6+
7+
from pylab import *
8+
import numpy as np
9+
from matplotlib import patches, path
10+
nan = np.nan
11+
Path = path.Path
12+
13+
# NOTE: All of these tests assume that path.simplify is set to True
14+
# (the default)
15+
16+
@image_comparison(baseline_images=['clipping'])
17+
def test_clipping():
18+
t = np.arange(0.0, 2.0, 0.01)
19+
s = np.sin(2*pi*t)
20+
21+
fig = plt.figure()
22+
ax = fig.add_subplot(111)
23+
ax.plot(t, s, linewidth=1.0)
24+
ax.set_ylim((-0.20, -0.28))
25+
ax.set_xticks([])
26+
ax.set_yticks([])
27+
fig.savefig('clipping')
28+
29+
@image_comparison(baseline_images=['overflow'])
30+
def test_overflow():
31+
x = np.array([1.0,2.0,3.0,2.0e5])
32+
y = np.arange(len(x))
33+
34+
fig = plt.figure()
35+
ax = fig.add_subplot(111)
36+
ax.plot(x,y)
37+
ax.set_xlim(xmin=2,xmax=6)
38+
ax.set_xticks([])
39+
ax.set_yticks([])
40+
41+
fig.savefig('overflow')
42+
43+
@image_comparison(baseline_images=['clipping_diamond'])
44+
def test_diamond():
45+
x = np.array([0.0, 1.0, 0.0, -1.0, 0.0])
46+
y = np.array([1.0, 0.0, -1.0, 0.0, 1.0])
47+
48+
fig = plt.figure()
49+
ax = fig.add_subplot(111)
50+
ax.plot(x, y)
51+
ax.set_xlim(xmin=-0.6, xmax=0.6)
52+
ax.set_ylim(ymin=-0.6, ymax=0.6)
53+
ax.set_xticks([])
54+
ax.set_yticks([])
55+
56+
fig.savefig('clipping_diamond')
57+
58+
def test_noise():
59+
np.random.seed(0)
60+
x = np.random.uniform(size=(5000,)) * 50
61+
62+
fig = plt.figure()
63+
ax = fig.add_subplot(111)
64+
p1 = ax.plot(x, solid_joinstyle='round', linewidth=2.0)
65+
ax.set_xticks([])
66+
ax.set_yticks([])
67+
68+
path = p1[0].get_path()
69+
transform = p1[0].get_transform()
70+
path = transform.transform_path(path)
71+
simplified = list(path.iter_segments(simplify=(800, 600)))
72+
73+
assert len(simplified) == 2662
74+
75+
def test_sine_plus_noise():
76+
np.random.seed(0)
77+
x = np.sin(np.linspace(0, np.pi * 2.0, 1000)) + np.random.uniform(size=(1000,)) * 0.01
78+
79+
fig = plt.figure()
80+
ax = fig.add_subplot(111)
81+
p1 = ax.plot(x, solid_joinstyle='round', linewidth=2.0)
82+
ax.set_xticks([])
83+
ax.set_yticks([])
84+
85+
path = p1[0].get_path()
86+
transform = p1[0].get_transform()
87+
path = transform.transform_path(path)
88+
simplified = list(path.iter_segments(simplify=(800, 600)))
89+
90+
assert len(simplified) == 279
91+
92+
@image_comparison(baseline_images=['simplify_curve'])
93+
def test_simplify_curve():
94+
pp1 = patches.PathPatch(
95+
Path([(0, 0), (1, 0), (1, 1), (nan, 1), (0, 0), (2, 0), (2, 2), (0, 0)],
96+
[Path.MOVETO, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CLOSEPOLY]),
97+
fc="none")
98+
99+
fig = plt.figure()
100+
ax = fig.add_subplot(111)
101+
ax.add_patch(pp1)
102+
ax.set_xticks([])
103+
ax.set_yticks([])
104+
ax.set_xlim((0, 2))
105+
ax.set_ylim((0, 2))
106+
107+
fig.savefig('simplify_curve')
108+
109+
if __name__=='__main__':
110+
import nose
111+
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

0 commit comments

Comments
 (0)