Skip to content

Instantly share code, notes, and snippets.

@vwrs
Last active November 25, 2018 05:52
Show Gist options
  • Save vwrs/7bb6398f2628f84de58fe1642f13fd87 to your computer and use it in GitHub Desktop.
Save vwrs/7bb6398f2628f84de58fe1642f13fd87 to your computer and use it in GitHub Desktop.
matplotlib utils
import matplotlib.pyplot as plt
import seaborn as sns
from collections import Counter
def counter_plot(values, max_count=len(set(values)),
figsize=(17,5), dpi=80,
fontsize=12, rotation=90,
xoffset=.05, yoffset=.1):
c = Counter(values)
l, v = zip(*c.most_common(max_count))
i = list(range(len(l)))
plt.figure(figsize=figsize, dpi=dpi)
sns.barplot(i, v)
plt.xticks(i, l, rotation=rotation,
fontsize=fontsize)
plt.yticks(fontsize=fontsize)
plt.ylabel('counts', fontsize=fontsize+5)
for ii, vv in zip(i, v):
plt.text(ii-xoffset, vv+yoffset, vv,
color='m', rotation=40,
fontsize=fontsize)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment