如何在matplotlib中创建密度图?
在RI中,可以通过执行以下操作来创建所需的输出: data = c(rep(1.5, 7), rep(2.5, 2), rep(3.5, 8), rep(4.5, 3), rep(5.5, 1), rep(6.5, 8)) plot(density(data, bw=0.5)) 在python(带有matplotlib)中,我得到的最接近的是一个简单的直方图: import matplotlib.pyplot as plt data = [1.5]*7 + [2.5]*2 + [3.5]*8 + [4.5]*3 + [5.5]*1 + [6.5]*8 plt.hist(data, bins=6) plt.show() 我还尝试了normed = True参数,但除了尝试使高斯拟合直方图外什么也没有。 我的最新尝试是围绕scipy.stats和gaussian_kde,以下是网上的示例,但到目前为止我一直没有成功。