def histg(x,bins):
n, bins = plt.hist(x, bins,normed=True)
plt.show()
return (plt)
我想通过将数据的最小值和最大值分成相等的间隔来创建bin。 考虑样本数据
X : 67 45 22 48 91 46 52 61 58.
我如何在功能中做到这一点?
答案 0 :(得分:0)
尝试一下:
x = [67, 45, 22, 48, 91, 46, 52, 61, 58]
bins = np.linspace(min(x), max(x), 10)
def histg(x,bins):
n = plt.hist(x, bins,normed=True)
plt.show()
return n
histg(x, bins) # Store in some variable in case you want to further process