前提・実現したいこと
PythonのMatplotlibでhist()
を用いて度数分布 , ヒストグラムを作成したいと思っています。
Python
1import os 2import re 3import glob 4import numpy as np 5import pandas as pd 6import matplotlib.pyplot as plt 7import japanize_matplotlib 8 9Age_List = [23, 22, 23, 22, 24, 20, 22, 24, 1029, 28, 25, 25, 26, 27, 28, 27, 25, 25, 27, 25, 25, 1132, 32, 32, 33, 33, 32, 33, 32, 30, 33, 32, 1235, 39, 38, 38, 37, 35, 38, 35, 35, 38, 35, 37, 1343, 44, 40, 41, 44, 41, 40, 43, 44, 41, 41, 44, 43, 42, 40, 44, 42, 41, 42, 1447, 49, 49, 46, 48, 45, 49, 49, 49, 49, 49, 48, 46, 49, 45, 48, 49, 48, 1554, 52, 54, 53, 53, 54, 50, 51, 52, 54, 1658, 56, 58, 58, 55, 57, 56, 56, 55] 17 18fig = plt.figure(figsize=(5.5,3.5)) 19ax = fig.add_subplot(1,1,1) 20 21n, bins, _ = ax.hist(Age_List, bins=10, range=(30, 50),rwidth=0.8) 22 23 24xs = (bins[:-1] + bins[1:])/2 25ys = n.astype(int) 26 27for x, y in zip(xs, ys): 28 plt.text(x, y, str(y), horizontalalignment="center")
ヒストグラムを作成するにあたり、Age_List
の値を基に30代未満 , 3032歳 , 3234歳...48~50歳,50以上
のような度数分布で描画したいです。
しかし、今の段階だと30歳未満 , 50歳以上の分布が表示されず除外されてしまいます。
Age_List
の値を基に集計を行えって、度数分布表を作成すれば恐らく作れるとは思うのですがmatplotlib上で簡単に作成する方法があれば教えて欲しいです。
よろしくお願いいたします。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/10/19 14:27