繁体   English   中英

导入的shapefile外部的掩码区域(底图/ matplotlib)

[英]Mask area outside of imported shapefile (basemap/matplotlib)

我正在通过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)

我认为我刚发现的这篇文章可以给你一些帮助。 但我不确定这是一个完整的答案。

http://basemaptutorial.readthedocs.org/en/latest/clip.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM