Skip to content

Instantly share code, notes, and snippets.

@CalebFenton
Created September 28, 2017 16:53
Show Gist options
  • Save CalebFenton/fb25d9e9e9a4450e95f89776fd40836e to your computer and use it in GitHub Desktop.
Save CalebFenton/fb25d9e9e9a4450e95f89776fd40836e to your computer and use it in GitHub Desktop.
Graphing Code Popularity
#!/usr/bin/env python
import ujson as json
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.ticker as plticker
def graph_class_counts():
with open('class-hashes-full.json', 'rb') as f:
j = json.load(f)
counts = j['classHashToCount'].values()
counts.sort()
line_plot(
'class_hash_popularity.png',
range(0, len(counts)),
counts,
title='Class Hash Popularity',
ylabel='count',
)
def graph_method_counts():
with open('method-hashes-full.json', 'rb') as f:
j = json.load(f)
counts = j['methodHashToCount'].values()
counts.sort()
line_plot(
'method_hash_popularity.png',
range(0, len(counts)),
counts,
title='Method Hash Popularity',
ylabel='count',
)
def line_plot(path, x, y, title=None, ylabel=None):
fig = plt.figure(figsize=(24,16))
ax = fig.add_subplot(111) #yticks=range(0, len(probas), 10000)
ax.set_xlim([0, len(x)])
ax.set_ylim([0, max(y)])
ax.xaxis.set_major_locator(plticker.MaxNLocator(nbins=30))
ax.xaxis.set_minor_locator(plticker.AutoMinorLocator())
ax.yaxis.set_major_locator(plticker.MaxNLocator(nbins=20))
ax.yaxis.set_minor_locator(plticker.AutoMinorLocator())
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_linewidth(0.5)
ax.spines['left'].set_linewidth(0.5)
ax.grid(which='both')
ax.grid(which='minor', alpha=0.2)
ax.grid(which='major', alpha=0.5)
ax.set_ylabel(ylabel)
plt.title(title)
ax.plot(x, y)
plt.tight_layout()
fig.savefig(path, dpi=300)
plt.close('all')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment