-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_md_or_do.py
80 lines (57 loc) · 1.89 KB
/
is_md_or_do.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
# Nov 2013
# MSSG
# import pylab
import sys
from collections import Counter
# import reportlab
import matplotlib.pyplot as plt
import numpy
#########3# Code to make barchart
# Open file
f1 = open('first1e3.csv','r')
# Read in file
all_lines = f1.readlines()
# Cut out the header line
lines = all_lines[1:len(all_lines)]
print " len(lines) = ", len(lines)
typedat=[]
# Pull out the state -- i found it has to be in one of those 4 columns, and the first occurrence of an exactly 2 letter string does it
i = 0
for line in lines:
i+=1
dat = line.split(',')
type = dat[10].replace('"','')
typedat.append(type)
types = Counter(typedat)
print types
lentypes = len(types)
print lentypes
# Separate the dict into 2 arrays
typelist = [x[0] for x in types.most_common()] # Pull out type names
freq = [x[1] for x in types.most_common()] # Pull out freq per type
print typelist
print freq
# Create full range for the types
xaxis = numpy.arange(lentypes) # the x locations for the groups
width = 1.05 # the width of the bars -- unity means no space at all between them
# This creates the fig -- syntax of line must be exactly as this for some reason
fig,xfig = plt.subplots()
# This draws the bars on the graph
rects = xfig.bar(xaxis, freq, width, color='g')
# Add the labels
xfig.set_title('Number of MDs by Type') # Title at top
xfig.set_ylabel('Number') # y-label
xfig.set_xticks(xaxis+width) # Where to place the x-labels
xfig.set_xticklabels( typelist ) # Names of x-labels (list of strings)
# To label the freq at the top of each bar
def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
xfig.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
ha='center', va='bottom')
autolabel(rects)
plt.show()
# for j in range(0,len(dat)):
# print j,dat[j]
# sys.exit()