Python, ValueError: not enough values to unpack (expected 2, got 1)

Python, ValueError: not enough values to unpack (expected 2, got 1)

我在 pcolormesh 行收到一个值错误(ValueError:没有足够的值来解压(预期 2,得到 1),知道如何处理这个问题。

import numpy as np 
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

data = np.loadtxt('out.txt')
lats = data[:,0]
lons = data[:,1]
codg_tec = data[:,2]

m = Basemap(projection = 'merc', llcrnrlon= -9, llcrnrlat=19, urcrnrlon= 12, urcrnrlat=37,       resolution= 'i')
m.drawcoastlines()

lon = np.all(lons)
lat = np.all(lats)

x, y = np.meshgrid(lon, lat)

lon, lat = np.meshgrid(lons, lats)
x, y = m(lon, lat)

cb = m.pcolormesh(x, y, codg_tec, shading='flat', cmap=plt.cm.jet)
m.colorbar(location ='right')
cbar = m.colorbar(cb, location = 'right', pad = '10%')

m.drawmapboundary()
m.drawmapscale()
m.drawmeridians(np.arange(-9,12,5), labels=[False,False,False,True])
m.drawparallels(np.arange(19,38,5), labels=[True,False,False,False])
m.drawstates()
m.drawcountries()

plt.title('CODG-vTEC on 02-01-2015')
plt.show()

根据 matplotlib.pyplot.pcolormesh 文档:

[x,y] 是必需的(一个 list

cb = m.pcolormesh([x, y], codg_tec, shading='flat', cmap=plt.cm.jet)

你可以试试这个, cb, your_arg = m.pcolormesh(x, y, codg_tec, shading='flat', cmap=plt.cm.jet)