Vytvoření histogramu

Statistical Thinking in Python (Part 1)

Justin Bois

Teaching Professor at the California Institute of Technology

Výsledky voleb 2008 v kolísavých státech USA

Data získána z Data.gov (https://www.data.gov/)

ch1-2.003.png

Statistical Thinking in Python (Part 1)

Vytvoření histogramu

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()
Statistical Thinking in Python (Part 1)

Vždy popište osy

Statistical Thinking in Python (Part 1)

Výsledky voleb 2008 v kolísavých státech USA

Data získána z Data.gov (https://www.data.gov/)

ch1-2.013.png

Statistical Thinking in Python (Part 1)

Histogramy s různým dělením

Data získána z Data.gov (https://www.data.gov/)

ch1-2.015.png

Statistical Thinking in Python (Part 1)

Nastavení přihrádek histogramu

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

Statistical Thinking in Python (Part 1)

Nastavení přihrádek histogramu

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

ch1-2.027.png

Statistical Thinking in Python (Part 1)

Seaborn

  • Vynikající balíček pro statistickou vizualizaci dat postavený na Matplotlib, který napsal Michael Waskom
Statistical Thinking in Python (Part 1)

Nastavení stylu Seaborn

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()
Statistical Thinking in Python (Part 1)

Histogram ve stylu Seaborn

ch1-2.038.png

1 Data získána z Data.gov (https://www.data.gov/)
Statistical Thinking in Python (Part 1)

Lass uns üben!

Statistical Thinking in Python (Part 1)

Preparing Video For Download...