PythonのMatplotlibを使って箱ひげ図をつくる

Category :

箱ひげ図

Python3とmatplotlibを使って箱ひげ図を作ろうと思います。

箱ひげ図とは

箱ひげ図はデータのばらつき具合を調べるために使われ、データを最小値、最大値、第1四分位、第2四分位、第3四分位に分けて表現します。

最小値、最大値

文字通り、データの最小値と最大値を選びます。

第1四分位

データ全体の1/4の部分が第1四分位です。

第2四分位

データ全体の1/2の部分が第2四分位にあたり、中央値とも呼ばれます。

第3四分位

データ全体の3/4の部分が第3四分位です。

箱ひげ図のプログラム https://bellcurve.jp/statistics/course/5220.html

箱ひげ図のプログラム

import matplotlib.pyplot as plt
# データの作成
date1 = [36,82,77,52,65]#数学の点数
date2 = [20,75,58,45,67]#理科の点数
hige = (date1, date2)
fig = plt.figure()
ax = fig.add_subplot(111)
# 箱ひげ図をつくる
bp = ax.boxplot(hige)
ax.set_xticklabels(['math', 'science'])
plt.title('Box plot')
plt.grid()
plt.xlabel('point')
plt.ylabel('value')
plt.title('Box plot')
plt.ylim([0,100])
plt.show()
TOP
© 2021 uichi