底图和numpy 2d数组

时间:2014-04-15 22:41:47

标签: python numpy matplotlib-basemap

我在光栅中有一些物理数据作为numpy数组(电磁场密度)。我知道纬度,角的经度和像素大小。我知道如何通过将坐标从lat,lon转换为x,y逐点转换来将我的栅格与底图绘图结合起来,但由于阵列中有超过10k点,因此需要花费太多时间。 那么,是否有另一种方法可以在Basemap上绘制数据?

1 个答案:

答案 0 :(得分:1)

width = 200
height = 300
lllon, lllat, urlon, urlat = -144.99499512, -59.95500183, -65.03500366, 60.00500107
dlon = (urlon-lllon) / width
dLat = (urlat-lllat) / height
baseArray = np.fromfunction(lambda y,x: (1000.0 / (width + height)) * (y+x), (height, width), dtype = float)
lons = np.arange(lllon, urlon, dlon)
lats = np.arange(lllat, urlat, dLat)
lons, lats = np.meshgrid(lons, lats)

fig = plt.figure()
plt.title("The Plot")
m = Basemap(projection='cyl',
          resolution = 'c',
          llcrnrlon = lllon, llcrnrlat = lllat,
          urcrnrlon =urlon, urcrnrlat = urlat
)

m.pcolormesh(lons, lats, baseArray, shading='flat', latlon=True)
plt.show()