The story of Milk Boy who won the M-1 Grand Prix the other day
"Cornflakes"
In the episode that appeared in ・ I don't know why the pentagon of nutritional balance is so wide. ・ Because the pentagon written on the package is insanely huge
It is spoken in the story. Let's visualize it with Python immediately.
In Python, with a visualization library called matplotlib Pentagon-like nutrients You can draw a radar chart.
import matplotlib.pyplot as plt
import pandas as pd
from math import pi
%matplotlib inline
df = pd.DataFrame({
'group' : ['Corn flakes','Bread'],
'Cal' : [250,50],
'Fe' : [260,100],
'VitaminA' : [290,80],
'VitaminB1': [220,60],
'VitaminB2': [305,120],
'Niacin' : [195,60],
'VitaminC' : [280,85],
'VitaminD' : [280,80],
'VitaminE' : [300,190]
})
categories=list(df)[1:]
N = len(categories)
plt.figure(figsize=(16,9))
ax = plt.subplot(111, polar=True)
angles = [n / float(N) * 2 * pi for n in range(N)] + angles[:1]
#Corn flakes
values = df.loc[0].drop('group').values.flatten().tolist()
values += values[:1]
plt.xticks(angles[:-1], categories, color='grey', size=20)
ax.set_rlabel_position(0)
plt.yticks([100,200,300], ["100","200","300"], color="grey", size=10)
plt.ylim(0,300)
ax.plot(angles, values, linewidth=2, linestyle='solid')
ax.fill(angles, values, 'b', alpha=0.1)
#Bread
values = df.loc[1].drop('group').values.flatten().tolist()
values += values[:1]
plt.xticks(angles[:-1], categories, color='grey', size=20)
ax.set_rlabel_position(0)
plt.yticks([100,200,300], ["100","200","300"], color="green", size=10)
plt.ylim(0,300)
ax.plot(angles, values, linewidth=1, linestyle='solid')
ax.fill(angles, values, 'b', alpha=0.1)
plt.show()
Create data for display with pandas Just decide the display angle and specify the data to be displayed there It is an easy plot.
Common cornflakes nutrients Because there were many things that were compared with bread I draw bread and corn flakes together.
Nutrient numbers are appropriate
However···
There was no way that a pentagon was enough for nutrients.
However, the area is insanely large as the story street! !!
It can also be a source of visualization It was a story of a milk boy.
Sure, Milk Boy It goes well with programming.
I'm looking forward to more material coming out.
Recommended Posts