Automatisera figurer från data

Introduktion till datavisualisering med Matplotlib

Ariel Rokem

Data Scientist

Varför automatisera?

  • Enkelhet och snabbhet
  • Flexibilitet
  • Robusthet
  • Reproducerbarhet
Introduktion till datavisualisering med Matplotlib

Hur många olika typer av data finns det?

summer_2016_medals["Sport"]
ID
62            Rowing
65         Taekwondo
73          Handball
             ...
134759      Handball
135132    Volleyball
135205        Boxing
Name: Sport, Length: 976, dtype: object
Introduktion till datavisualisering med Matplotlib

Hämta unika värden från en kolumn

sports = summer_2016_medals["Sport"].unique()

print(sports)
['Rowing' 'Taekwondo' 'Handball' 'Wrestling' 
'Gymnastics' 'Swimming' 'Basketball' 'Boxing' 
'Volleyball' 'Athletics']
Introduktion till datavisualisering med Matplotlib

Stapeldiagram över längd per sport

fig, ax = plt.subplots()

for sport in sports:
  sport_df = summer_2016_medals[summer_2016_medals["Sport"] == sport]

ax.bar(sport, sport_df["Height"].mean(), yerr=sport_df["Height"].std())
ax.set_ylabel("Height (cm)") ax.set_xticklabels(sports, rotation=90) plt.show()
Introduktion till datavisualisering med Matplotlib

Figur genererad automatiskt från data

Introduktion till datavisualisering med Matplotlib

Nu kör vi en övning!

Introduktion till datavisualisering med Matplotlib

Preparing Video For Download...