我有lat=[13.7,21,23.7,10.6,34.5,20.7,33.1,15.5]
lon=[65.7,87.5,69.8,98.3,67,79.8,88.8,77.9]
和
val=[234,310,287,279,298,280,279,321]
如何在地图上对这些数据进行空间绘图?我的代码看起来像
lat=[13.7,21,23.7,10.6,34.5,20.7,33.1,15.5]
lon=[65.7,87.5,69.8,98.3,67,79.8,88.8,77.9]
val=[234,310,287,279,298,280,279,321]
lon, lat = np.meshgrid(lon, lat)
m = Basemap(projection='merc', resolution=None,
llcrnrlat=0, urcrnrlat=40,
llcrnrlon=60, urcrnrlon=100, )
m.contourf(lon,lat,val)
答案 0 :(得分:1)
要使用contourf
,您需要栅格数据(即,如果您有8x8 lon-lat栅格,则需要64个z值)。由于只有三元组(lon,lat,z),因此最好使用tricontourf图。但是,底图不具有该功能,但是为tri
函数提供了附加的contourf
关键字:
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits import basemap
lat=np.array([13.7,21,23.7,10.6,34.5,20.7,33.1,15.5])
lon=np.array([65.7,87.5,69.8,98.3,67,79.8,88.8,77.9])
val=np.array([234,310,287,279,298,280,279,321])
#lon, lat = np.meshgrid(lon, lat) <-- do not use this
m = basemap.Basemap(projection='merc', resolution=None,
llcrnrlat=0, urcrnrlat=40,
llcrnrlon=60, urcrnrlon=100, )
##need to convert coordinates
x,y = m(lon,lat)
##add the `tri=True` kwarg
m.contourf(x,y,val, tri=True)
plt.show()