我试图在地图上绘制温度的插值数据。
a = [(41.42,2.11,24),(40.40,2.2,15),(41.9,3,6),(40.3,4.4,10),(42.3,4.1,15),(39.2,3.5,16)]
结构是:a = [(lat,lon,data),(lat,lon,data)...(lat,lon,data)]
我试试这段代码:
lats = [ x[0] for x in a ]
lons = [ x[1] for x in a ]
data = [ x[2] for x in a ]
lat_min = min(lats)
lat_max = max(lats)
lon_min = min(lons)
lon_max = max(lons)
data_min = min(data)
data_max = max(data)
spatial_resolution = 0.5
fig = plt.figure()
x = np.array(lons)
y = np.array(lats)
z = np.array(data)
xinum = (lon_max - lon_min) / spatial_resolution
yinum = (lat_max - lat_min) / spatial_resolution
xi = np.linspace(lon_min, lon_max + spatial_resolution, xinum)
yi = np.linspace(lat_min, lat_max + spatial_resolution, yinum)
xi, yi = np.meshgrid(xi, yi)
zi = griddata(x, y, z, xi, yi)
m = Basemap(.....)
lat, lon = m.makegrid(zi.shape[1], zi.shape[0])
x,y = m(lat, lon)
m.contourf(x, y, zi)
plt.show()
当我测试代码时,我会收到更多未来的警告:
FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
这个错误:
ValueError: Unknown interpolation method array([[ 2.11, 3.04, 3.97, 4.9 ],
[ 2.11, 3.04, 3.97, 4.9 ],
[ 2.11, 3.04, 3.97, 4.9 ],
[ 2.11, 3.04, 3.97, 4.9 ],
[ 2.11, 3.04, 3.97, 4.9 ],
[ 2.11, 3.04, 3.97, 4.9 ]]) for 1 dimensional data
会发生什么?我该怎么办?
谢谢!
马克