-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpl_scatter_contour_demo.py
104 lines (73 loc) · 2.35 KB
/
mpl_scatter_contour_demo.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
Test program to try out AstroML scatter_contour
"""
# use native matplotlib or matplotlib.pyplot
#import matplotlib as plt
import matplotlib.pyplot as plt
from astroML.plotting import scatter_contour
import numpy as np
#print 'np.random.get_state(): ', np.random.get_state()
plt.figure(num=None, figsize=(10, 10))
n=10000
np.random.seed(1)
xdata=np.random.normal(0.0, 1.0, n)
np.random.seed(2)
ydata=np.random.normal(0.0, 1.0, n)
iplot=1
plt.subplot(2,2,iplot)
#plt.xlabel('X')
#plt.ylabel('Y')
plt.subplot(2,2,iplot)
plt.title("scatter: '.', s=2, color='red'")
label='data: ' + str(len(xdata))
marker='.'
plt.scatter(xdata, ydata, marker=marker, s=2, color='red',
label=label)
plt.legend(loc=2)
plt.xlim(-5.0, 5.0)
plt.ylim(-5.0, 5.0)
# using mplot to get same result as scatter
# ms=1 makes invisible points
iplot = iplot+1
plt.subplot(2,2,iplot)
plt.title("plot: '.', ms=2, color='r'")
label='data: ' + str(len(xdata))
marker='.'
color='red'
plt.plot(xdata, ydata, marker=marker, ms=2, lw=0, color=color,
markeredgecolor=color, label=label)
plt.legend(loc=2)
plt.xlim(-5.0, 5.0)
plt.ylim(-5.0, 5.0)
iplot=iplot+1
plt.subplot(2,2,iplot)
threshold=10
# note ax=plt within arguments
plt.title("scatter_contour: '.', markersize=2, color='red'")
label='data: ' + str(len(xdata))
scatter_contour(xdata, ydata, threshold=threshold, log_counts=True,
histogram2d_args=dict(bins=40),
ax=plt,
plot_args=dict(marker='.', linestyle='none',
markersize=2, color='red',
markeredgecolor='red',
label=label),
contour_args=dict(cmap=plt.cm.rainbow))
plt.xlim(-5.0, 5.0)
plt.ylim(-5.0, 5.0)
iplot=iplot+1
plt.subplot(2,2,iplot)
threshold=10
plt.title("scatter_contour: 'o', markersize=2, color='blue'")
scatter_contour(xdata, ydata, threshold=threshold, log_counts=True,
histogram2d_args=dict(bins=20),
ax=plt,
plot_args=dict(marker='o', linestyle='none',
markersize=2, color='blue',
markeredgecolor='blue'),
contour_args=dict(cmap=plt.cm.rainbow))
plt.xlim(-5.0, 5.0)
plt.ylim(-5.0, 5.0)
plt.suptitle('matplotlib scatter_contour tests')
plt.savefig('mpl_scatter_contour_demo.png')
plt.show()