Tambury

Tambury OP t1_itnx41u wrote

Here you go! Apologies for the uncommented spaghetti code.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

pizzasplit=pd.read_csv(r'D:\Downloads\pizza time splits - Sheet1.csv')

fig, ax = plt.subplots(figsize=(8, 6),dpi=150)

xlim=45.5
ylim=1005

pizzasplit['Elapsed time']=pizzasplit['Elapsed time'].map(lambda x: pd.to_timedelta(x).seconds/60)

plt.scatter(pizzasplit['Elapsed time'],pizzasplit.Millimetres,color='b')
plt.plot(pizzasplit['Elapsed time'],pizzasplit.Millimetres,color='b')
ax.axhline(1000,color='r',xmax=45/xlim)
ax.axhline(604,color='b',xmin=36.91/xlim,xmax=45/xlim)
plt.text(22.5, 1000, '1 metre of pizza', fontsize=12, va='center', ha='center', backgroundcolor='w')
plt.text(37, 620, 'Defeat', fontsize=12, va='baseline', ha='left')

ax.axvline(30,color='g',ymax=1000/ylim)
ax.axvline(45,color='g',ymax=1000/ylim)
plt.text(29.5, 30, 'Time limit for free pizza + $100', fontsize=10, va='bottom', ha='center', rotation=90)
plt.text(44.5, 30, 'Time limit for commemorative t-shirt', fontsize=10, va='bottom', ha='center', rotation=90)

x=np.arange(0, 31, 1)
y=1000*x/30
plt.plot(x,y,color='g',linestyle='dashed',alpha=0.4)

x=np.arange(0, 46, 1)
y=1000*x/45

plt.plot(x,y,color='g',linestyle='dashed',alpha=0.4)

plt.xticks(np.arange(0, 46, step=5))
plt.yticks(np.arange(0, 1001, step=250))
plt.xlim(0,xlim)
plt.ylim(0,ylim)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)

ax.grid(linestyle="--", linewidth=0.5, color='.25', alpha=0.3, zorder=-10)

plt.xlabel('Elapsed time (minutes)')
plt.ylabel('Pizza consumed (mm)')

def make_patch_spines_invisible(ax):
    ax.set_frame_on(True)
    ax.patch.set_visible(False)
    for sp in ax.spines.values():
        sp.set_visible(False)

fig.subplots_adjust(right=0.75)

par1 = ax.twinx()
par2 = ax.twinx()

# Offset the right spine of par2.  The ticks and label have already been
# placed on the right by twinx above.
par1.spines["right"].set_position(("axes", 1.02))
par2.spines["right"].set_position(("axes", 1.15))
# Having been created by twinx, par2 has its frame off, so the line of its
# detached spine is invisible.  First, activate the frame but make the patch
# and spines invisible.
make_patch_spines_invisible(par2)
# Second, show the right spine.
par2.spines["right"].set_visible(True)
par1.spines['top'].set_visible(False)

par1.set_ylim(0, (ylim/1000)*max(pizzasplit.Slices))
par2.set_ylim(0, (ylim/1000)*max(pizzasplit.kJ))

par1.set_yticks(np.arange(0, 25, step=4))

par1.set_ylabel("Slices")
par2.set_ylabel("Energy (kJ)")

tkw = dict(size=4, width=1.5)
ax.tick_params(axis='y', **tkw)
par1.tick_params(axis='y', **tkw)
par2.tick_params(axis='y', **tkw)
ax.tick_params(axis='x', **tkw)

plt.tight_layout()

Data input CSV file below

kJ,Millimetres,Slices,Elapsed time
0,0,0,00:00:00
728.5,41.66666667,1,00:01:04
1457,83.33333333,2,00:02:08
2185.5,125,3,00:02:50
2914,166.6666667,4,00:03:38
3642.5,208.3333333,5,00:04:37
4371,250,6,00:05:15
5099.5,291.6666667,7,00:06:04
5828,333.3333333,8,00:07:03
6556.5,375,9,00:08:28
7285,416.6666667,10,00:10:08
8013.5,458.3333333,11,00:12:28
8742,500,12,00:15:41
9470.5,541.6666667,13,00:21:30
10199,583.3333333,14,00:28:52
10563.25,604.1666667,14.5,00:36:55
11656,666.6666667,16,
12384.5,708.3333333,17,
13113,750,18,
13841.5,791.6666667,19,
14570,833.3333333,20,
15298.5,875,21,
16027,916.6666667,22,
16755.5,958.3333333,23,
17484,1000,24,
2

Tambury OP t1_itlh22b wrote

Keep in mind the $100 was thrown in by the boss on the day who had obviously sized up the competitor and taken a punt that he wouldn't make it.

The owner did say that quite a few people actually complete it, but he has made a lot more money out of people attempting the challenge and failing than free pizza given away.

9

Tambury OP t1_itleyom wrote

Cheers, I appreciate the feedback. It's a difficult concept to convey pizza as a linear unit, especially when most people intuitively think of pizza as an 11-ish inch diameter circle cut into 8 slices. In hindsight, keeping the headline '1 metre of pizza' but using number of slices as the primary axis.

As for energy, I wasn't quite thinking of global appeal when I made it. Kilojoules is standard for energy and is on product labels, though calories is understood. Perhaps I could have added ticks to the other side of the energy axis in Cal at the risk of clutter.

7

Tambury OP t1_itk3jb6 wrote

Edit: here's a picture of pizza https://i.redd.it/v5bgqgkzzqv91.jpg

A friend of mine recently attempted a pizza-eating challenge at a local Italian restaurant. The store sells rectangular pizza that is 200mm (8in) wide, and is sold in linear increments of 250mm (10in) or 6 slices.

The store has a challenge of eating a 1 metre (39in) length of pizza - 24 slices.

  • If the pizza is consumed in under 45 minutes, the victor wins a t-shirt.
  • If the pizza could be eaten in under 30 minutes, the pizza would also be free.
  • The owner was feeling particularly generous (or confident) that day, and also offered a $100 cash prize for the 30 minute target.

The data was collected by recording the time measured by a restaurant-supplied stopwatch after each of the 24 pizza slices was fully consumed. Elapsed time was recorded in a spreadsheet app on a smartphone. The graph was plotted using Matplotlib in a Python Notebook. Energy contained within the pizza was approximated by back-calculating the nutritional information of a similarly topped fast-food pizza into a unit rate of energy per area, and then applying that to the area of the pizza.

After 14.5 slices, he admitted defeat and called it.

352