我正在尝试在 python 中创建直方图,用一些自定义值对 y 轴值进行标准化。为此,我想这样做:
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] 数组提供相同数量的元素,例如删除其中一个的第一个或最后一个元素?
hist[1] 包含您制作直方图的限制。我想您可能想获得这些间隔的中心,例如:
x = [hist[0], 0.5*(hist[1][1:]+hist[1][:-1])]
然后剧情应该没问题吧?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)