Skip to content

Instantly share code, notes, and snippets.

@jsundram
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsundram/3b0f138d12d02a079708 to your computer and use it in GitHub Desktop.
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.
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