以下是我想要绘制PDF的数据。 https://gist.github.com/ecenm/cbbdcea724e199dc60fe4a38b7791eb8#file-64_general-out
以下是脚本
import numpy as np
import matplotlib.pyplot as plt
import pylab
data = np.loadtxt('64_general.out')
H,X1 = np.histogram( data, bins = 10, normed = True, density = True) # Is this the right way to get the PDF ?
plt.xlabel('Latency')
plt.ylabel('PDF')
plt.title('PDF of latency values')
plt.plot(X1[1:], H)
plt.show()
当我绘制上述内容时,我得到以下内容。
答案 0 :(得分:1)
这是近似 PDF的合法方式。由于np.histogram使用各种技术对值进行分级,因此您无法获得输入中每个数字的确切频率。要获得更精确的近似值,您应计算每个数字的出现次数并将其除以总计数。此外,由于这些是离散值,因此绘图可以绘制为点或条,以给出更正确的印象。
在离散情况下,频率之和应等于1.在连续情况下,您可以使用np.trapz()
来近似积分。