Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
from scipy.interpolate import interp1d
import numpy as np
import shlex
import subprocess as sp
import prettyplotlib as ppl
from matplotlib import pyplot as plt
from matplotlib.ticker import FuncFormatter
import io
from pandas import read_csv
cmd = "git log --no-merges --date=short --pretty='format:%ad\t%H\t%aN'"
p = sp.Popen(shlex.split(cmd), stdout=sp.PIPE)
# p.wait() will likely just hang if the log is long enough because the
# stdout buffer will fill up
stdout, _ = p.communicate()
table = read_csv(io.StringIO(stdout.decode('utf-8')), sep='\t',
names=['date', 'hash', 'author'], index_col=0,
table = table.to_period(freq='W')
commits_per_period = table.hash.groupby(level=0).aggregate(len)
dates = [ for p in commits_per_period.index]
ncommits = commits_per_period.values
fn = interp1d(range(len(dates)), ncommits, 'cubic', bounds_error=False)
fig, ax = plt.subplots(1)
fig.set_size_inches((8, 2))
x = np.linspace(0, len(dates), 1000)
ppl.fill_between(x, 0, fn(x))
ax.set_title('Number of commits to Astropy')
ax.set_xlim(0, len(dates))
ax.set_ylim(0, max(ncommits) + 0.1 * max(ncommits))
ax.xaxis.set_ticks(np.linspace(0, len(dates) - 1, 8)[1:-1])
def formatter(x, p):
if x >= len(dates):
return ''
return dates[int(x)].strftime('%b %Y')
formatter = FuncFormatter(formatter)
# There must be a btter way to do this...
plt.setp(plt.xticks()[1], rotation=30)
fig.savefig('graph.png', bbox_inches='tight')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment