정량 비교: 히스토그램

Matplotlib으로 시작하는 데이터 시각화

Ariel Rokem

Data Scientist

히스토그램

Matplotlib으로 시작하는 데이터 시각화

막대 그래프 다시 보기

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()

Matplotlib으로 시작하는 데이터 시각화

히스토그램 소개

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()

Matplotlib으로 시작하는 데이터 시각화

레이블이 필요합니다

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()

Matplotlib으로 시작하는 데이터 시각화

히스토그램 사용자 지정: 구간 수 설정

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()

Matplotlib으로 시작하는 데이터 시각화

히스토그램 사용자 지정: 구간 경계 설정

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()

Matplotlib으로 시작하는 데이터 시각화

히스토그램 사용자 지정: 투명도

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()
Matplotlib으로 시작하는 데이터 시각화

histtype이 step인 히스토그램

Matplotlib으로 시작하는 데이터 시각화

직접 히스토그램을 만들어 보세요!

Matplotlib으로 시작하는 데이터 시각화

Preparing Video For Download...