Last active
August 29, 2015 14:27
-
-
Save jsundram/3b0f138d12d02a079708 to your computer and use it in GitHub Desktop.
What does a geek do when ordering pizza? Plots the price per square inch, of course.
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
import matplotlib.pyplot as plt | |
import numpy as np | |
# TBD: Account for the (variable) price of toppings. | |
prices = [(8, 7.55), (12, 14.95), (14, 17.75), (16, 20.45), (18, 22.95)] | |
area = lambda d: 3.14*(.5*d)**2 | |
price_per_sqinch = [p / area(d) for (d, p) in prices] | |
f, ax = plt.subplots() | |
index = range(len(prices)) | |
bars = plt.bar(index, price_per_sqinch) | |
middle = bars[0].get_width() / 2 | |
plt.xticks(np.array(index) + middle, [str(d) for (d, p) in prices]) | |
plt.xlabel("diameter (inches)") | |
plt.ylabel("price per square inch ($)") | |
plt.title("Extreme Pizza Cost Curve") | |
plt.savefig("./pizza_price_per_sq_inch.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment