Last active
May 18, 2017 20:36
-
-
Save derekargueta/3c39ebf973dffda3644303f22ec0a8a0 to your computer and use it in GitHub Desktop.
This file contains 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
from collections import OrderedDict, Counter | |
import matplotlib.pylab as plt | |
def general_percentage_graph(data, xaxis=None, yaxis=None, filename=None) -> None: | |
plt.clf() | |
thresholds = Counter(data) | |
sorted_map = OrderedDict(sorted(thresholds.items())) | |
lists = sorted_map.items() | |
if len(lists) == 0: | |
return | |
x, y = zip(*lists) | |
# convert to percentages: value / total which will be between 0 and 1, | |
# multiply by 100 to make a percentage | |
tot = sum(y) | |
y = [(tmp / tot) * 100 for tmp in y] | |
plt.plot(x, y) | |
if xaxis: | |
plt.xlabel(xaxis) | |
if yaxis: | |
plt.ylabel(yaxis) | |
if filename: | |
plt.savefig(filename, format='eps', dpi=500) | |
else: | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment