Python Matplotlib:更改每个y值
在列表1按轴进行分组后,我需要更改第二个图形中的所有y值,例如Python Matplotlib:更改每个y值,python,matplotlib,Python,Matplotlib,在列表1按轴进行分组后,我需要更改第二个图形中的所有y值,例如**2/total。hist import matplotlib.pyplot as plt figure1, axes1 = plt.subplots(nrows = 2, ncols = 1) axes1[0].hist(x = list1, bins = np.arange(start = 0, stop = 6, step = 1), density = True) axes1[1].hist(x = list1, bins
**2/total
。hist
import matplotlib.pyplot as plt
figure1, axes1 = plt.subplots(nrows = 2, ncols = 1)
axes1[0].hist(x = list1, bins = np.arange(start = 0, stop = 6, step = 1), density = True)
axes1[1].hist(x = list1, bins = np.arange(start = 0, stop = 6, step = 1), density = True)
figure1.show()
我该怎么做
第二个图形的结果bin值应为:
0 0.217322
1 0.045818
2 0.038517
3 0.007593
4 0.000658
5 0.000115
这对密度不起作用。您想自己使用
h, bins = np.histogram(list, bins=np.arange(6))
将h归一化为
h = h/np.sum(h)
或者实际计算密度
db = np.array(np.diff(bins), float)
h = h/db/h.sum()
并手动绘制直方图,或者使用一些mpl方法(在每个箱子中放置一个计数,并将实数解析为权重)
plt.hist(bins[:-1]+0.5, bins=bins, weights=h)
plt.hist(bins[:-1]+0.5, bins=bins, weights=h**2)
或者使用专用软件包绘制已计算的直方图(mpl目前不直接支持)
这不适用于密度。您希望自己使用
h, bins = np.histogram(list, bins=np.arange(6))
将h归一化为
h = h/np.sum(h)
或者实际计算密度
db = np.array(np.diff(bins), float)
h = h/db/h.sum()
并手动绘制直方图,或者使用一些mpl方法(在每个箱子中放置一个计数,并将实数解析为权重)
plt.hist(bins[:-1]+0.5, bins=bins, weights=h)
plt.hist(bins[:-1]+0.5, bins=bins, weights=h**2)
或者使用专用软件包绘制已计算的直方图(mpl目前不直接支持)
什么是
总计
?什么是总计
?