【发布时间】:2017-10-23 12:18:37
【问题描述】:
在 Python 中,我已经估计了分布模型的密度参数,我想在分布直方图上方绘制密度函数。在 R 中,它类似于使用选项 prop=TRUE。
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
# initialization of the list "data"
# estimation of the parameter, in my case, mean and variance of a normal distribution
plt.hist(data, bins="auto") # data is the list of data
# here I would like to draw the density above the histogram
plt.show()
我想最棘手的部分是让它合身。
编辑:我已经根据第一个答案尝试了这个:
mean = np.mean(logdata)
var = np.var(logdata)
std = np.sqrt(var) # standard deviation, used by numpy as a replacement of the variance
plt.hist(logdata, bins="auto", alpha=0.5, label="données empiriques")
x = np.linspace(min(logdata), max(logdata), 100)
plt.plot(x, mlab.normpdf(x, mean, std))
plt.xlabel("log(taille des fichiers)")
plt.ylabel("nombre de fichiers")
plt.legend(loc='upper right')
plt.grid(True)
plt.show()
【问题讨论】:
-
不清楚您在寻找什么。您可以添加有关您希望该图形外观的屏幕截图/更多信息吗?与往常一样,Minimal, Complete, and Verifiable Example 将极大地帮助您获得好的答案。
-
在这里。是的,你是对的,一个例子胜于一千个解释!但我仍然认为我的解释很清楚......
-
如果您不想使用
normed = True,我已经添加了一个解决方案。
标签: python matplotlib statistics