【发布时间】:2018-08-31 13:31:10
【问题描述】:
我正在尝试在 Python 上使用 Basemap(我也愿意尝试 cartopy)在地图上绘制一些天气数据。现在,我的天气数据看起来像this。我的数据源基本上是一个数组,每个位置对应于网格的一个正方形,每个值表示该正方形应该是的颜色。用于生成此图像的代码如下所示,其中网格的每个正方形等于 1000 m:
grid_0 = np.asarray(dec.split())
grid_1=np.reshape(grid_0,(n_cols,n_rows))
grid_2 = grid_1.astype(float)
# Make plot
plt.figure(figsize=(30,30))
fig, ax = plt.subplots()
plt.axis('off')
cax = ax.imshow(grid_2, interpolation='nearest', cmap=cmap)
我有关于地理上网格下角所在位置的信息。我相信在地图上绘制它的最佳方法是以某种方式使用 contourf() 函数,但我对 Basemap 很陌生,无法找到将其转换为 contourf() 可以理解的方法的方法。绘制我正在使用 Basemap 的地图,其中 lon_air 和 lat_air 是某个机场的坐标:
fig=figure(1, figsize=(19, 15))
m = Basemap(projection='cyl', llcrnrlon=lon_air-25, llcrnrlat=lat_air-15,
urcrnrlon=lon_air+25, urcrnrlat=lat_air+15, resolution='h', area_thresh=10000)
m.drawstates(linewidth=0.5, color='black', zorder=4)
m.drawcountries(linewidth=2.0, color='white', zorder=3)
m.drawmapboundary(fill_color='#e5f5ff')
m.fillcontinents(color='#DFDFDF', zorder=1)
m.scatter(lon_air, lat_air,marker='o',color='k', zorder=10)
x0, y0 = lon_air-((360*920)/(4*np.pi*6371)),lat_air-((360*920)/(4*np.pi*6371))
x1, y1 = lon_air+((360*920)/(4*np.pi*6371)), lat_air+((360*920)/(4*np.pi*6371))
im = plt.imshow(plt.imread('./pngs/9905.png'), extent=(x0, x1, y0, y1), zorder=2)
plt.show()
如果有人认为需要更多详细信息,我将编辑该帖子。在此先感谢大家!
【问题讨论】:
-
分别生成天气数据和地图需要什么代码?如果我们能看到我们可能能够更好地帮助您合并两者
-
正如 Aaron 所说,在问题中包含代码可以帮助您找到答案。看起来好像您正试图从提供的照片中绘制一些雷达数据。我会调查一下metpy (link to docs),看看里面是否有任何适用于你的东西。
-
感谢你们的 cmets 伙计们,我编辑了我的问题,现在我会检查 MetPy :)
标签: python dictionary matplotlib-basemap weather contourf