我想在python中創建一個直方圖圖,用一些自定義值對y軸值進行標準化。對於這一點,我想這樣做是這樣的:有沒有辦法在numpy.hist中返回相同長度的數組?
import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt('foo.bar')
fig = plt.figure()
ax = fig.add_subplot(111)
hist=np.histogram(data, bins=(1.0, 1.5 ,2.0,2.5,3.0))
x=[hist[0]*5,hist[1]]
ax.plot(x[0], x[1], 'o')
但當然,最後的行給出:
ValueError: x and y must have same first dimension
有沒有辦法迫使np.hist給予相同數量的x [0]和x [1]數組的元素,例如通過刪除其中一個元素的第一個或最後一個元素?
太棒了,正是我需要的! – mannaroth