ValueError:权重应与x具有相同的形状

时间:2016-02-17 14:22:16

标签: python matplotlib

在我的代码中

    from __future__ import division
    import sys
    import math
    import os
    import matplotlib.pyplot as plt

    def get_pt_t(event):
        pt_list=[]
        pdg_list=[]
        for particle in event:
            p = FourMomentum()
            if particle.pid in [-11,11,13,-13] and particle.status==1 :
                p += particle
                pt_list.append(p.pt)
                break
        return pt_list
values_x= []

PT_t=[]
PT_t.append(pt_list)

...

现在,pt_list为每个"粒子"保存一个列表,例如[x,y]。上面 - 现在,在尝试绘制时

nbins=300
# prepare the plots
gs1 = gridspec.GridSpec(2, 1, height_ratios=[5,1.2])
gs1.update(wspace=0, hspace=0) # set the spacing between axes.

# plot the Three main curve for the pt
ax = plt.subplot(gs1[0])
wgts_list = []
wgts_list.append( [1,2])
n3, nbins, _ = ax.hist(PT_t, bins=nbins, histtype='step', linewidth=0,weights=wgts_list)

但我得到

n3, nbins, _ = ax.hist(PT_t, bins=nbins, histtype='step', linewidth=0,weights=wgts_list)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py", line 8290, in hist
    raise ValueError('weights should have the same shape as x')
ValueError: weights should have the same shape as x

我认为问题在于我想绘制一个列表(PT_t),但不能在权重参数中指定权重列表。

0 个答案:

没有答案