我正在尝试制作包含垃圾箱数量的历史图。 之后,我想在垃圾箱后面绘制线图,但我无法绘制线图。我可以寻求帮助吗?
plt.hist(df1_small['fz'], bins=[-5, -4.5, -4, -3.5, -3,-2.5,-2,-1.5,-1,-0.5,0, 0.5, 1,1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5])
sns.kdeplot(df1_small['fz'],fill=True, color = 'Red')
df1_small['fz'].plot(kind = "kde")
plt.xlabel('Distribution of fz of small particles')
plt.xlim(-5, 5)
plt.show()
这是我的代码。 我得到的情节是这样的:
如果您注意到了,线图只是 0 的直线。
如何在所有垃圾箱后面画线?
plt.hist
的轮廓,请使用返回的 counts
和 bins
:
width = 0.5
counts, bins, bars = plt.hist(data=df1_small, x='fz', bins=np.arange(-5, 5.5, width))
plt.plot(bins[:-1] + width/2, counts)
sns.kdeplot
:
density=True
以绘制概率密度而不是原始计数clip
KDE 到直方图范围bw_adjust
plt.hist(data=df1_small, x='fz', bins=np.arange(-5, 5.5, 0.5), density=True)
sns.kdeplot(data=df1_small, x='fz', clip=(-5, 5), bw_adjust=0.1)