-
Notifications
You must be signed in to change notification settings - Fork 0
/
mat_test.py
34 lines (28 loc) · 1.01 KB
/
mat_test.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
import matplotlib
from cgitb import text
from mailcap import show
from matplotlib.pyplot import scatter, axis, xlabel, ylabel
from numpy import genfromtxt, zeros, sqrt
durl = 'http://datasets.flowingdata.com/crimeRatesByState2005.csv'
rdata = genfromtxt(durl, dtype='S8,f,f,f,f,f,f,f,i', delimiter=',')
rdata[0] = zeros(8) # cutting the label's titles
rdata[1] = zeros(8) # cutting the global statistics
x = []
y = []
color = []
area = []
for data in rdata:
x.append(data[1]) # murder
y.append(data[5]) # burglary
color.append(data[6]) # larceny_theft
area.append(sqrt(data[8])) # population
# plotting the first eigth letters of the state's name
text(data[1], data[5],
data[0], size=11, horizontalalignment='center')
# making the scatter plot
sct = scatter(x, y, c=color, s=area, linewidths=2, edgecolor='w')
sct.set_alpha(0.75)
axis([0, 11, 200, 1280])
xlabel('Murders per 100,000 population')
ylabel('Burglaries per 100,000 population')
show()