Skip to content

Instantly share code, notes, and snippets.

@willettk
Created July 18, 2014 10:00
Show Gist options
  • Save willettk/b89da6aace158fc8348e to your computer and use it in GitHub Desktop.
Save willettk/b89da6aace158fc8348e to your computer and use it in GitHub Desktop.
Plot bar chart of nationalities for conference attendees of AGN clustering conference; Garching, July 2014
import pandas
import numpy
import matplotlib.pyplot as plt
data = pandas.read_csv('/Users/willettk/Astronomy/meetings/garching2014/participants.csv',names=('person','country','institution'))
darkblue = '#00008b'
colordict = {
'Germany' : ('yellow','red','black'),
'Japan' : ('white','red'),
'UK' : (darkblue,'white','red'),
'USA' : ('red','white',darkblue),
'Greece' : ('white','blue'),
'Finland' : ('blue','white'),
'Mexico' : ('green','white','red'),
'Australia' : ('red','white',darkblue),
'Spain' : ('yellow','red'),
'Sweden' : ('blue','yellow'),
'Chile' : ('red','white','blue'),
'India' : ('green','white','orange'),
'Netherlands' : ('blue','white','red'),
'Italy' : ('red','white','green'),
'Canada' : ('white','red')
}
vc = data['country'].value_counts()
N = 5
ind = numpy.arange(len(vc)) # the x locations for the groups
width = 0.9 # the width of the bars: can also be len(x) sequence
eps = 0.0001
c1,c2,c3 = [],[],[]
w1,w2,w3 = [],[],[]
for k,v in vc.iterkv():
colors = colordict[k]
if len(colors) == 2:
w1.append(v * (1./(2.+eps)))
w2.append(v * (1./(2.+eps)))
w3.append(v * (1.-2./(2.+eps)))
c1.append(colors[0])
c2.append(colors[1])
c3.append('black')
else:
w1.append(v * 1/3.)
w2.append(v * 1/3.)
w3.append(v * 1/3.)
c1.append(colors[0])
c2.append(colors[1])
c3.append(colors[2])
w12 = [x+y for x,y in zip(w1,w2)]
p1 = plt.bar(ind, w1, width, color=c1)
p2 = plt.bar(ind, w2, width, color=c2, bottom=w1)
p3 = plt.bar(ind, w3, width, color=c3, bottom=w12)
plt.ylabel('Count')
plt.title('Participating institutions - AGN clustering meeting 2014')
plt.ylim(0,13)
locs,labels = plt.xticks(ind+width/2., list(vc.index))
for l in labels:
l.set_rotation(45)
l.set_horizontalalignment('right')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment