Skip to content

Instantly share code, notes, and snippets.

@mhawksey
Last active May 4, 2016 20:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhawksey/99ea405a8aac79f4bc0becfbc950479b to your computer and use it in GitHub Desktop.
Save mhawksey/99ea405a8aac79f4bc0becfbc950479b to your computer and use it in GitHub Desktop.
FutureLearn Stats Recipes Enrollment Summary
# Enrollment summary graph
# Extension of https://github.com/psychemedia/futurelearnStatsSketches/blob/master/notebooks/FutureLearn%20Stats%20Recipes.ipynb
import matplotlib.ticker as tkr
cat = ['Enrolled learners', 'Visited at least one step', 'Completed at least one step', 'Commented at least once']
count = [len(enrolled_learners),
len(enrolled_learners.intersection(stepstart_learners)),
len(enrolled_learners.intersection(stepcomplete_learners)),
len(commenting_learners)
]
data = {'cat': cat,
'count': count}
plt.rc("figure", figsize=(10, 5))
summary = pd.DataFrame(data, columns=['cat', 'count'])
ax = summary.plot(kind='barh', color='fuchsia', title='{} enrollment summary'.format(COURSE_SHORTNAME))
ax.invert_yaxis()
ax.set_yticklabels(summary.cat)
ax.legend(loc=4, prop={'size':13})
ax.get_xaxis().set_major_formatter(
tkr.FuncFormatter(lambda x, p: format(int(x), ',')))
for item in ([ax.title, ax.xaxis.label, ax.yaxis.label] +
ax.get_xticklabels() + ax.get_yticklabels()):
item.set_fontsize(13)
rect_labels = []
for rect, label in zip(ax.patches, count):
width = rect.get_width()
xloc = 0.98*width
clr = 'white'
align = 'right'
yloc = rect.get_y() + rect.get_height()/2.0
label = ax.text(xloc, yloc, '{:,.0f}'.format(width), horizontalalignment=align,
verticalalignment='center', color=clr, weight='bold',
clip_on=True)
rect_labels.append(label)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment