use*_*622 7 python matplotlib esri shapefile matplotlib-basemap
我正在通过Matplotlib在美国和加拿大东海岸的底图上绘制数据.除了基础层(填充的等高线图),我使用Matplotlib的readshapefile工具在数据顶部覆盖了这个焦点区域的shapefile.

我想知道如何掩盖shapefile之外的所有网格数据.我显然可以通过Matplotlib做一个maskocean命令,但我仍然留在圣劳伦斯以西的填充轮廓.现在有人怎么做?我在线搜索没有太多运气.
def make_map(lon,lat,param):
fig, ax = plt.subplots()
ax.axis('off')
x1 = -83.
x2 = -57.
y1 = 37.
y2 = 50.
projection='merc'
resolution='h'
m = Basemap(projection=projection, llcrnrlat=y1, urcrnrlat=y2, llcrnrlon=x1,
urcrnrlon=x2, resolution=resolution)
x,y = m((lon-360.),lat)
m.ax = ax
my_cmap = cm.get_cmap('coolwarm')
pp = m.contourf(x, y, param, 30, cmap=my_cmap, extend='both')
m.drawmapscale(-67, 39.5, -70, 43.5, 500, fontsize=8, barstyle='fancy')
return fig, m, x, y
def drawstates(ax, shapefile='../StateProv_UTMrp'):
shp = m.readshapefile(shapefile, 'states',zorder = 1, drawbounds=True)
for nshape, seg in enumerate(m.states):
poly = Polygon(seg, facecolor='w',alpha=0.0, edgecolor='k')
ax.add_patch(poly)
fig, m, x, y = make_map(lon, lat, param)
drawstates(m.ax)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1680 次 |
| 最近记录: |