Skip to content

Commit 0ac2765

Browse files
committed
responses to feedback from anntzer
1 parent b95363a commit 0ac2765

File tree

2 files changed

+21
-46
lines changed

2 files changed

+21
-46
lines changed

lib/matplotlib/path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ def _fast_from_codes_and_verts(cls, verts, codes, internals=None):
208208
def _update_values(self):
209209
self._simplify_threshold = rcParams['path.simplify_threshold']
210210
self._should_simplify = (
211+
self._simplify_threshold > 0 and
211212
rcParams['path.simplify'] and
212213
len(self._vertices) >= 128 and
213-
(self._codes is None or np.all(self._codes <= Path.LINETO)) and
214-
self._simplify_threshold > 0
214+
(self._codes is None or np.all(self._codes <= Path.LINETO))
215215
)
216216
self._has_nonfinite = not np.isfinite(self._vertices).all()
217217

lib/matplotlib/tests/test_simplification.py

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
from matplotlib.path import Path
1616

1717

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():
2320
plt.rcParams['path.simplify'] = True
21+
plt.rcParams['path.simplify_threshold'] = 0.1111111111111111
2422

23+
24+
@image_comparison(baseline_images=['clipping'], remove_text=True)
25+
def test_clipping(set_simplify_and_threshold):
2526
t = np.arange(0.0, 2.0, 0.01)
2627
s = np.sin(2*np.pi*t)
2728

@@ -31,9 +32,7 @@ def test_clipping():
3132

3233

3334
@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):
3736
x = np.array([1.0, 2.0, 3.0, 2.0e5])
3837
y = np.arange(len(x))
3938

@@ -43,9 +42,7 @@ def test_overflow():
4342

4443

4544
@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):
4946
x = np.array([0.0, 1.0, 0.0, -1.0, 0.0])
5047
y = np.array([1.0, 0.0, -1.0, 0.0, 1.0])
5148

@@ -55,9 +52,7 @@ def test_diamond():
5552
ax.set_ylim(ymin=-0.6, ymax=0.6)
5653

5754

58-
def test_noise():
59-
plt.rcParams['path.simplify'] = True
60-
55+
def test_noise(set_simplify_and_threshold):
6156
np.random.seed(0)
6257
x = np.random.uniform(size=(50000,)) * 50
6358

@@ -72,9 +67,7 @@ def test_noise():
7267
assert simplified.vertices.size == 25888
7368

7469

75-
def test_antiparallel_simplification():
76-
plt.rcParams['path.simplify'] = True
77-
70+
def test_antiparallel_simplification(set_simplify_and_threshold):
7871
def _get_simplified(x,y):
7972
fig, ax = plt.subplots()
8073
p1 = ax.plot(x, y)
@@ -148,9 +141,7 @@ def _get_simplified(x,y):
148141
[ 1. , 0.5]],
149142
simplified.vertices[:-2, :])
150143

151-
def test_sine_plus_noise():
152-
plt.rcParams['path.simplify'] = True
153-
144+
def test_sine_plus_noise(set_simplify_and_threshold):
154145
np.random.seed(0)
155146
x = (np.sin(np.linspace(0, np.pi * 2.0, 50000)) +
156147
np.random.uniform(size=(50000,)) * 0.01)
@@ -167,9 +158,7 @@ def test_sine_plus_noise():
167158

168159

169160
@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):
173162
pp1 = patches.PathPatch(
174163
Path([(0, 0), (1, 0), (1, 1), (np.nan, 1), (0, 0), (2, 0), (2, 2),
175164
(0, 0)],
@@ -184,19 +173,15 @@ def test_simplify_curve():
184173

185174

186175
@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):
190177
fig, ax = plt.subplots()
191178
ax.add_patch(plt.Rectangle((0, 0), 1, 1, fill=False, hatch="/"))
192179
ax.set_xlim((0.45, 0.55))
193180
ax.set_ylim((0.45, 0.55))
194181

195182

196183
@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):
200185
fig, ax = plt.subplots()
201186
t = np.arange(65536)
202187
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():
209194
assert simplified.vertices.size == 38
210195

211196

212-
def test_start_with_moveto():
213-
plt.rcParams['path.simplify'] = True
214-
197+
def test_start_with_moveto(set_simplify_and_threshold):
215198
# Should be entirely clipped away to a single MOVETO
216199
data = b"""
217200
ZwAAAAku+v9UAQAA+Tj6/z8CAADpQ/r/KAMAANlO+v8QBAAAyVn6//UEAAC6ZPr/2gUAAKpv+v+8
@@ -266,9 +249,7 @@ def test_throw_rendering_complexity_exceeded():
266249

267250

268251
@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):
272253
dat = (0, 1, 0, 2, 0, 3, 0, 4, 0, 5)
273254
fig = plt.figure(figsize=(2, 1))
274255
fig.subplots_adjust(left=0, bottom=0, wspace=0, hspace=0)
@@ -284,9 +265,7 @@ def test_clipper():
284265

285266

286267
@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):
290269
x = np.array([0, 1, 2, 1, 0, -1, 0, 1] + [1] * 128)
291270
y = np.array([1, 1, 2, 1, 0, -1, 0, 0] + [0] * 128)
292271

@@ -296,9 +275,7 @@ def test_para_equal_perp():
296275

297276

298277
@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):
302279
x = np.linspace(0, 3.14 * 2, 3000)
303280
y = np.sin(x)
304281
x[::100] = np.nan
@@ -308,9 +285,7 @@ def test_clipping_with_nans():
308285
ax.set_ylim(-0.25, 0.25)
309286

310287

311-
def test_clipping_full():
312-
plt.rcParams['path.simplify'] = True
313-
288+
def test_clipping_full(set_simplify_and_threshold):
314289
p = Path([[1e30, 1e30]] * 5)
315290
simplified = list(p.iter_segments(clip=[0, 0, 100, 100]))
316291
assert simplified == []

0 commit comments

Comments
 (0)