我读过这个问题-Overlay shape file on matplotlib,我不确定它是否适用于我,但是我有一个我国家的shapefile,我想把GRIB文件中的降水数据叠加到shapefile上。这是使用pygrib和matplotlib。我对使用基线图。海岸线()和基本地图.国家()因为它在shapefile中可用。我想用我自己的shapefile覆盖它。我该怎么做?在
#!/usr/bin/python3.4
import numpy as np
import pygrib
import shapefile
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
grbs = pygrib.open('00020000')
grb = grbs.select(name='Total Precipitation')[0]
data = grb.values
lat,lon = grb.latlons()
m=Basemap(projection='mill',lat_ts=10,llcrnrlon=lon.min(), \
urcrnrlon=lon.max(),llcrnrlat=lat.min(),urcrnrlat=lat.max(), \
resolution='c')
m.readshapefile("adm3.shp")
x,y=m(lon,lat)
cs = m.pcolormesh(x,y,data,shading='flat',cmap=plt.cm.jet)
m.drawparallels(np.arange(-90.,80.,5.),labels=[1,0,0,0])
m.drawmeridians(np.arange(-180.,180.,5.),labels=[0,0,0,1])
plt.colorbar(cs,orientation='vertical')
plt.title('Precipitation Plot')
plt.show()
我不确定我是否理解,因为你的代码似乎基本上可以工作。我做了一些改变:
resolution
中的{None
,因为您不会使用内置的海岸线m.readshapefile
需要name
参数使用
还有一些被嘲弄的数据和国家边界,我得到的数据如下:
相关问题 更多 >
编程相关推荐