Last active
November 25, 2018 05:52
-
-
Save vwrs/7bb6398f2628f84de58fe1642f13fd87 to your computer and use it in GitHub Desktop.
matplotlib utils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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