Created
October 31, 2014 22:55
-
-
Save brouhaha/3ee9b853ba98558be084 to your computer and use it in GitHub Desktop.
bag_inventory.py
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
#!/usr/bin/python | |
# dailyprogrammer challenge #186 Bag Inventory | |
# Eric Smith <[email protected]> 2014-10-31 | |
import numpy as np, matplotlib.colors as mc, matplotlib.pyplot as plt | |
candy = {} | |
with open('186_easy.txt') as f: | |
for line in f.readlines(): | |
line = line.strip() | |
if line in candy: | |
candy[line] += 1 | |
else: | |
candy[line] = 1 | |
names = sorted(candy.keys()) | |
counts = [candy[n] for n in names] | |
colors = mc.hsv_to_rgb(np.array([[(1.0 * hue / len(names), 1.0, 1.0) for hue in range(len(names))]]))[0] | |
fig = plt.figure(figsize=[10, 10]) | |
ax = fig.add_subplot(111) | |
ax.pie(counts, labels = names, colors = colors, explode = [0.05] * len(names), autopct='%1.1f%%') | |
ax.set_title("Candy by type, total count = %d" % sum(counts)) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment