Skip to content

Commit d2dc510

Browse files
committed
Added tests
1 parent 4b652c3 commit d2dc510

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

lib/matplotlib/tests/test_artist.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,8 @@ def draw(self, renderer, extra):
562562

563563
assert 'aardvark' == art.draw(renderer, 'aardvark')
564564
assert 'aardvark' == art.draw(renderer, extra='aardvark')
565+
566+
567+
def test_artist_seed_update():
568+
martist.Artist().set_sketch_params(seed=2345)
569+
assert mpl.rcParams['path.sketch_seed'] == 2345

lib/matplotlib/tests/test_path.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,18 @@ def test_make_compound_path_stops():
243243
assert np.sum(compound_path.codes == Path.STOP) == 0
244244

245245

246+
def test_xkcd_seed_update():
247+
with plt.xkcd(seed=2000):
248+
assert rcParams['path.sketch_seed'] == 2000
249+
250+
246251
@image_comparison(['xkcd.png'], remove_text=True)
247252
def test_xkcd():
248253
np.random.seed(0)
249254

250255
x = np.linspace(0, 2 * np.pi, 100)
251256
y = np.sin(x)
252-
# we should be able to update seed through xkcd or Artist().set_sketch_params
253-
rcParams['path.sketch_seed'] = 19680801
254-
with plt.xkcd(seed=0):
257+
with plt.xkcd():
255258
fig, ax = plt.subplots()
256259
ax.plot(x, y)
257260

@@ -264,16 +267,33 @@ def test_xkcd_marker():
264267
y1 = x
265268
y2 = 5 - x
266269
y3 = 2.5 * np.ones(8)
267-
# we should be able to update seed through xkcd or Artist().set_sketch_params
268-
rcParams['path.sketch_seed'] = 19680801
269270
with plt.xkcd():
270-
artist.Artist().set_sketch_params(seed=0)
271271
fig, ax = plt.subplots()
272272
ax.plot(x, y1, '+', ms=10)
273273
ax.plot(x, y2, 'o', ms=10)
274274
ax.plot(x, y3, '^', ms=10)
275275

276276

277+
@image_comparison(['xkcd_artist.png'], remove_text=True)
278+
def test_xkcd_artist():
279+
with plt.xkcd():
280+
rcParams['path.sketch'] = (2, 120, 40)
281+
artist.Artist().set_sketch_params(seed=19680801)
282+
pat, txt = plt.pie([10, 20, 30, 40], wedgeprops={'edgecolor': 'black'})
283+
plt.legend(pat, ['first', 'second', 'third', 'fourth'], loc='best')
284+
plt.plot()
285+
286+
287+
@image_comparison(['xkcd_seed.png'], remove_text=True)
288+
def test_xkcd_seed():
289+
with plt.xkcd():
290+
rcParams['path.sketch'] = (2, 120, 40)
291+
rcParams['path.sketch_seed'] = 2000
292+
pat, txt = plt.pie([10, 20, 30, 40], wedgeprops={'edgecolor': 'black'})
293+
plt.legend(pat, ['first', 'second', 'third', 'fourth'], loc='best')
294+
plt.plot()
295+
296+
277297
@image_comparison(['marker_paths.pdf'], remove_text=True)
278298
def test_marker_paths_pdf():
279299
N = 7

0 commit comments

Comments
 (0)