Comparații cantitative: histograme

Introducere în vizualizarea datelor cu Matplotlib

Ariel Rokem

Data Scientist

Histograme

Introducere în vizualizarea datelor cu Matplotlib

Din nou cu diagrama cu bare

fig, ax = plt.subplots()

ax.bar("Rowing", mens_rowing["Height"].mean())
ax.bar("Gymnastics", mens_gymnastics["Height"].mean())
ax.set_ylabel("Height (cm)") plt.show()

Introducere în vizualizarea datelor cu Matplotlib

Introducere în histograme

fig, ax = plt.subplots()

ax.hist(mens_rowing["Height"])
ax.hist(mens_gymnastics["Height"])
ax.set_xlabel("Height (cm)") ax.set_ylabel("# of observations") plt.show()

Introducere în vizualizarea datelor cu Matplotlib

Etichetele sunt necesare

ax.hist(mens_rowing["Height"], label="Rowing")
ax.hist(mens_gymnastics["Height"], label="Gymnastics")
ax.set_xlabel("Height (cm)")
ax.set_ylabel("# of observations")

ax.legend() plt.show()

Introducere în vizualizarea datelor cu Matplotlib

Personalizarea histogramelor: numărul de intervale

ax.hist(mens_rowing["Height"], label="Rowing", bins=5)
ax.hist(mens_gymnastics["Height"], label="Gymnastics", bins=5)
ax.set_xlabel("Height (cm)")
ax.set_ylabel("# of observations")
ax.legend()
plt.show()

Introducere în vizualizarea datelor cu Matplotlib

Personalizarea histogramelor: limitele intervalelor

ax.hist(mens_rowing["Height"], label="Rowing",
        bins=[150, 160, 170, 180, 190, 200, 210])

ax.hist(mens_gymnastics["Height"], label="Gymnastics",
        bins=[150, 160, 170, 180, 190, 200, 210])

ax.set_xlabel("Height (cm)")
ax.set_ylabel("# of observations")
ax.legend()
plt.show()

Introducere în vizualizarea datelor cu Matplotlib

Personalizarea histogramelor: transparență

ax.hist(mens_rowing["Height"], label="Rowing",
        bins=[150, 160, 170, 180, 190, 200, 210],
        histtype="step")

ax.hist(mens_gymnastics["Height"], label="Gymnastics",
        bins=[150, 160, 170, 180, 190, 200, 210],
        histtype="step")

ax.set_xlabel("Height (cm)")
ax.set_ylabel("# of observations")
ax.legend()
plt.show()
Introducere în vizualizarea datelor cu Matplotlib

Histogramă cu histtype „step"

Introducere în vizualizarea datelor cu Matplotlib

Creați propria histogramă!

Introducere în vizualizarea datelor cu Matplotlib

Preparing Video For Download...