Rita ett histogram

Statistiskt tänkande i Python (del 1)

Justin Bois

Teaching Professor at the California Institute of Technology

Valresultat 2008 i viktade delstater, USA

Data hämtad från Data.gov (https://www.data.gov/)

ch1-2.003.png

Statistiskt tänkande i Python (del 1)

Generera ett histogram

import matplotlib.pyplot as plt
_ = plt.hist(df_swing['dem_share'])
_ = plt.xlabel('percent of vote for Obama')
_ = plt.ylabel('number of counties')
plt.show()
Statistiskt tänkande i Python (del 1)

Märk alltid dina axlar

Statistiskt tänkande i Python (del 1)

Valresultat 2008 i viktade delstater, USA

Data hämtad från Data.gov (https://www.data.gov/)

ch1-2.013.png

Statistiskt tänkande i Python (del 1)

Histogram med olika indelningar

Data hämtad från Data.gov (https://www.data.gov/)

ch1-2.015.png

Statistiskt tänkande i Python (del 1)

Ange intervall i ett histogram

bin_edges = [0, 10, 20, 30, 40, 50,
                60, 70, 80, 90, 100]
_ = plt.hist(df_swing['dem_share'], bins=bin_edges)
plt.show()

ch1-2.022.png

Statistiskt tänkande i Python (del 1)

Ange intervall i ett histogram

_ = plt.hist(df_swing['dem_share'], bins=20)
plt.show()

ch1-2.027.png

Statistiskt tänkande i Python (del 1)

Seaborn

  • Ett utmärkt statistiskt visualiseringsbibliotek baserat på Matplotlib, skrivet av Michael Waskom
Statistiskt tänkande i Python (del 1)

Ange Seaborn-stil

import seaborn as sns
sns.set()
_ = plt.hist(df_swing['dem_share'])
_ = plt.xlabel('percent of vote for Obama')
_ = plt.ylabel('number of counties')
plt.show()
Statistiskt tänkande i Python (del 1)

Ett histogram med Seaborn-stil

ch1-2.038.png

1 Data hämtad från Data.gov (https://www.data.gov/)
Statistiskt tänkande i Python (del 1)

Nu kör vi en övning!

Statistiskt tänkande i Python (del 1)

Preparing Video For Download...