0

我正在尝试hist2d从 x,y 坐标列表中绘制 a ,但得到 a Value Error: too many values to unpack (expected 2)

代码是:

visuals = [[],[],[]]

with open('Wide_Single_timestamp2.csv') as csvfile :
    readCSV = csv.reader(csvfile, delimiter=',')
    n=0
    for row in readCSV :
        if n == 0 :
            n+=1
            continue
        visuals[0].append(list(map(float, row[2::2])))
        visuals[1].append(list(map(float, row[3::2])))

X = visuals[1]
Y = visuals[0]

fig, ax = plt.subplots(figsize = (8,7))
plt.grid(False)

data,x,y,p = plt.hist2d(X,Y, bins = 10, range = np.array([(-90, 90), (4, 140)]))
plt.imshow(data, interpolation = 'gaussian', origin = 'lower', extent = [-90,90,4,140], cmap = 'jet')

当我将列表减少为单行时,该代码有效:

Y = visuals[1][0]
X = visuals[0][0]

但我需要绘制更多的数据点。

4

1 回答 1

1

尝试使用extend而不是append通过另一个列表扩展列表。

也就是说,改变两行:

    visuals[0].extend(list(map(float, row[2::2])))
    visuals[1].extend(list(map(float, row[3::2])))
于 2018-02-07T03:30:37.873 回答