15
15
from matplotlib .path import Path
16
16
17
17
18
- # NOTE: All of these tests used to assume that path.simplify is set to True
19
- # but that is no longer the case.
20
-
21
- @image_comparison (baseline_images = ['clipping' ], remove_text = True )
22
- def test_clipping ():
18
+ @pytest .fixture
19
+ def set_simplify_and_threshold ():
23
20
plt .rcParams ['path.simplify' ] = True
21
+ plt .rcParams ['path.simplify_threshold' ] = 0.1111111111111111
24
22
23
+
24
+ @image_comparison (baseline_images = ['clipping' ], remove_text = True )
25
+ def test_clipping (set_simplify_and_threshold ):
25
26
t = np .arange (0.0 , 2.0 , 0.01 )
26
27
s = np .sin (2 * np .pi * t )
27
28
@@ -31,9 +32,7 @@ def test_clipping():
31
32
32
33
33
34
@image_comparison (baseline_images = ['overflow' ], remove_text = True )
34
- def test_overflow ():
35
- plt .rcParams ['path.simplify' ] = True
36
-
35
+ def test_overflow (set_simplify_and_threshold ):
37
36
x = np .array ([1.0 , 2.0 , 3.0 , 2.0e5 ])
38
37
y = np .arange (len (x ))
39
38
@@ -43,9 +42,7 @@ def test_overflow():
43
42
44
43
45
44
@image_comparison (baseline_images = ['clipping_diamond' ], remove_text = True )
46
- def test_diamond ():
47
- plt .rcParams ['path.simplify' ] = True
48
-
45
+ def test_diamond (set_simplify_and_threshold ):
49
46
x = np .array ([0.0 , 1.0 , 0.0 , - 1.0 , 0.0 ])
50
47
y = np .array ([1.0 , 0.0 , - 1.0 , 0.0 , 1.0 ])
51
48
@@ -55,9 +52,7 @@ def test_diamond():
55
52
ax .set_ylim (ymin = - 0.6 , ymax = 0.6 )
56
53
57
54
58
- def test_noise ():
59
- plt .rcParams ['path.simplify' ] = True
60
-
55
+ def test_noise (set_simplify_and_threshold ):
61
56
np .random .seed (0 )
62
57
x = np .random .uniform (size = (50000 ,)) * 50
63
58
@@ -72,9 +67,7 @@ def test_noise():
72
67
assert simplified .vertices .size == 25888
73
68
74
69
75
- def test_antiparallel_simplification ():
76
- plt .rcParams ['path.simplify' ] = True
77
-
70
+ def
9E88
test_antiparallel_simplification (set_simplify_and_threshold ):
78
71
def _get_simplified (x ,y ):
79
72
fig , ax = plt .subplots ()
80
73
p1 = ax .plot (x , y )
@@ -148,9 +141,7 @@ def _get_simplified(x,y):
148
141
[ 1. , 0.5 ]],
149
142
simplified .vertices [:- 2 , :])
150
143
151
- def test_sine_plus_noise ():
152
- plt .rcParams ['path.simplify' ] = True
153
-
144
+ def test_sine_plus_noise (set_simplify_and_threshold ):
154
145
np .random .seed (0 )
155
146
x = (np .sin (np .linspace (0 , np .pi * 2.0 , 50000 )) +
156
147
np .random .uniform (size = (50000 ,)) * 0.01 )
@@ -167,9 +158,7 @@ def test_sine_plus_noise():
167
158
168
159
169
160
@image_comparison (baseline_images = ['simplify_curve' ], remove_text = True )
170
- def test_simplify_curve ():
171
- plt .rcParams ['path.simplify' ] = True
172
-
161
+ def test_simplify_curve (set_simplify_and_threshold ):
173
162
pp1 = patches .PathPatch (
174
163
Path ([(0 , 0 ), (1 , 0 ), (1 , 1 ), (np .nan , 1 ), (0 , 0 ), (2 , 0 ), (2 , 2 ),
175
164
(0 , 0 )],
@@ -184,19 +173,15 @@ def test_simplify_curve():
184
173
185
174
186
175
@image_comparison (baseline_images = ['hatch_simplify' ], remove_text = True )
187
- def test_hatch ():
188
- plt .rcParams ['path.simplify' ] = True
189
-
176
+ def test_hatch (set_simplify_and_threshold ):
190
177
fig , ax = plt .subplots ()
191
178
ax .add_patch (plt .Rectangle ((0 , 0 ), 1 , 1 , fill = False , hatch = "/" ))
192
179
ax .set_xlim ((0.45 , 0.55 ))
193
180
ax .set_ylim ((0.45 , 0.55 ))
194
181
195
182
196
183
@image_comparison (baseline_images = ['fft_peaks' ], remove_text = True )
197
- def test_fft_peaks ():
198
- plt .rcParams ['path.simplify' ] = True
199
-
184
+ def test_fft_peaks (set_simplify_and_threshold ):
200
185
fig , ax = plt .subplots ()
201
186
t = np .arange (65536 )
202
187
p1 = ax .plot (abs (np .fft .fft (np .sin (2 * np .pi * .01 * t )* np .blackman (len (t )))))
@@ -209,9 +194,7 @@ def test_fft_peaks():
209
194
assert simplified .vertices .size == 38
210
195
211
196
212
- def test_start_with_moveto ():
213
- plt .rcParams ['path.simplify' ] = True
214
-
197
+ def test_start_with_moveto (set_simplify_and_threshold ):
215
198
# Should be entirely clipped away to a single MOVETO
216
199
data = b"""
217
200
ZwAAAAku+v9UAQAA+Tj6/z8CAADpQ/r/KAMAANlO+v8QBAAAyVn6//UEAAC6ZPr/2gUAAKpv+v+8
@@ -266,9 +249,7 @@ def test_throw_rendering_complexity_exceeded():
266
249
267
250
268
251
@image_comparison (baseline_images = ['clipper_edge' ], remove_text = True )
269
- def test_clipper ():
270
- plt .rcParams ['path.simplify' ] = True
271
-
252
+ def test_clipper (set_simplify_and_threshold ):
272
253
dat = (0 , 1 , 0 , 2 , 0 , 3 , 0 , 4 , 0 , 5 )
273
254
fig = plt .figure (figsize = (2 , 1 ))
274
255
fig .subplots_adjust (left = 0 , bottom = 0 , wspace = 0 , hspace = 0 )
EF10
@@ -284,9 +265,7 @@ def test_clipper():
284
265
285
266
286
267
@image_comparison (baseline_images = ['para_equal_perp' ], remove_text = True )
287
- def test_para_equal_perp ():
288
- plt .rcParams ['path.simplify' ] = True
289
-
268
+ def test_para_equal_perp (set_simplify_and_threshold ):
290
269
x = np .array ([0 , 1 , 2 , 1 , 0 , - 1 , 0 , 1 ] + [1 ] * 128 )
291
270
y = np .array ([1 , 1 , 2 , 1 , 0 , - 1 , 0 , 0 ] + [0 ] * 128 )
292
271
@@ -296,9 +275,7 @@ def test_para_equal_perp():
296
275
297
276
298
277
@image_comparison (baseline_images = ['clipping_with_nans' ])
299
- def test_clipping_with_nans ():
300
- plt .rcParams ['path.simplify' ] = True
301
-
278
+ def test_clipping_with_nans (set_simplify_and_threshold ):
302
279
x = np .linspace (0 , 3.14 * 2 , 3000 )
303
280
y = np .sin (x )
304
281
x [::100 ] = np .nan
@@ -308,9 +285,7 @@ def test_clipping_with_nans():
308
285
ax .set_ylim (- 0.25 , 0.25 )
309
286
310
287
311
- def test_clipping_full ():
312
- plt .rcParams ['path.simplify' ] = True
313
-
288
+ def test_clipping_full (set_simplify_and_threshold ):
314
289
p = Path ([[1e30 , 1e30 ]] * 5 )
315
290
simplified = list (p .iter_segments (clip = [0 , 0 , 100 , 100 ]))
316
291
assert simplified == []
0 commit comments