forked from astroML/astroML
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_devectorize.py
More file actions
40 lines (32 loc) · 891 Bytes
/
Copy pathtest_devectorize.py
File metadata and controls
40 lines (32 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import matplotlib
matplotlib.use('Agg') # don't display plots
import numpy as np
from numpy.testing import assert_
from matplotlib import image
import matplotlib.pyplot as plt
from cStringIO import StringIO
from astroML.plotting.tools import devectorize_axes
def test_devectorize_axes():
np.random.seed(0)
x, y = np.random.random((2, 1000))
# save vectorized version
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(x, y)
sio = StringIO()
fig.savefig(sio)
sio.reset()
im1 = image.imread(sio)
plt.close()
# save devectorized version
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(x, y)
devectorize_axes(ax, dpi=200)
sio = StringIO()
fig.savefig(sio)
sio.reset()
im2 = image.imread(sio)
plt.close()
assert_(im1.shape == im2.shape)
assert_((im1 != im2).sum() < 0.1 * im1.size)