如何绘制概率密度曲线?
How to plot the probability density curve?
我正在使用以下脚本绘制概率密度曲线,但它仅显示作为密度函数的直方图。求大神指教,求概率密度曲线的方法。
from matplotlib import pyplot
from numpy.random import normal
from numpy import mean[enter image description here][1]
from numpy import std
from scipy.stats import norm
data = pd.read_csv("a.txt", sep='\t',header=None)
sample = data[0]
sample_mean = mean(sample)
sample_std = std(sample)
dist = norm(sample_mean, sample_std)
values = [value for value in range(0, 1)]
probabilities = [dist.pdf(value) for value in values]
pyplot.hist(sample, bins=10, density=True)
plt.xlim(0,1)
pyplot.plot(values, probabilities, 'r')
pyplot.show()
如果你用的是R,这是一个很好的绘图网站https://www.r-graph-gallery.com/,你可以看看。尤其是ggplots的部分还是蛮有用的
如果您喜欢 python 这也是一个有用的网站 https://towardsdatascience.com/histograms-and-density-plots-in-python-f6bda88f5ac0。
希望这些对你有帮助。
我发现这很有用,我希望你也这样做
https://www.datacamp.com/community/tutorials/probability-distributions-python
我正在使用以下脚本绘制概率密度曲线,但它仅显示作为密度函数的直方图。求大神指教,求概率密度曲线的方法。
from matplotlib import pyplot
from numpy.random import normal
from numpy import mean[enter image description here][1]
from numpy import std
from scipy.stats import norm
data = pd.read_csv("a.txt", sep='\t',header=None)
sample = data[0]
sample_mean = mean(sample)
sample_std = std(sample)
dist = norm(sample_mean, sample_std)
values = [value for value in range(0, 1)]
probabilities = [dist.pdf(value) for value in values]
pyplot.hist(sample, bins=10, density=True)
plt.xlim(0,1)
pyplot.plot(values, probabilities, 'r')
pyplot.show()
如果你用的是R,这是一个很好的绘图网站https://www.r-graph-gallery.com/,你可以看看。尤其是ggplots的部分还是蛮有用的
如果您喜欢 python 这也是一个有用的网站 https://towardsdatascience.com/histograms-and-density-plots-in-python-f6bda88f5ac0。
希望这些对你有帮助。
我发现这很有用,我希望你也这样做 https://www.datacamp.com/community/tutorials/probability-distributions-python