量的比較:ヒストグラム

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...