我能用python制作直方图,但我不能添加密度曲线,我看到许多代码使用不同的方法在直方图上添加密度曲线,但我不知道如何使用我的代码
我添加了density=true,但无法获得直方图上的密度曲线
df = pd.DataFrame(np.random.randn(100, 4), columns=list('ABCD'))
X=df['A']
hist, bins = np.histogram(X, bins=10,density=True)
width = 0.7 * (bins[1] - bins[0])
center = (bins[:-1] + bins[1:]) / 2
plt.bar(center, hist, align='center', width=width)
plt.show()
熊猫还有
kde
图:输出:
这里是一种使用} 方法的方法。此外,评论中提到:
seaborn
的^{但是,} 和^{}
distplot
将是removed in a future version of seaborn。因此,替代方法是使用^{sns.histplot
sns.displot
相关问题 更多 >
编程相关推荐