| 
 
	积分120贡献 精华在线时间 小时注册时间2021-5-21最后登录1970-1-1 
 | 
 
| 
本帖最后由 qwe91100 于 2021-12-1 21:14 编辑
x
登录后查看更多精彩内容~您需要 登录 才可以下载或查看,没有帐号?立即注册 
  
 用的是萝卜大佬的maskout方法,也综合了晋陵小生大佬的去标签,加上了clabel条件,但是没有去除区域外等值线标签,问问各位大佬我该怎么改才能去掉区域外等值线,用的cartopy库
 复制代码def shp2clip(originfig,ax,shpfile,region,clabel = False):
    sf = shapefile.Reader(shpfile)
    for shape_rec in sf.shapeRecords():
#         print(shape_rec.record)
        if shape_rec.record[1] == region:  ####这里需要找到和region匹配的唯一标识符,record[]中必有一项是对应的。
            vertices = []
            codes = []
            pts = shape_rec.shape.points
            prt = list(shape_rec.shape.parts) + [len(pts)]
            for i in range(len(prt) - 1):
                for j in range(prt[i], prt[i+1]):
                    vertices.append((pts[j][0], pts[j][1]))
                codes += [Path.MOVETO]
                codes += [Path.LINETO] * (prt[i+1] - prt[i] -2)
                codes += [Path.CLOSEPOLY]
            clip = Path(vertices, codes)
            clip = PathPatch(clip, transform=ax.transData)
        if  clabel:
            clip_map_shapely = ShapelyPolygon(vertices)
            for text_object in clabel:
                if not clip_map_shapely.contains(ShapelyPoint(text_object.get_position())):
                    text_object.set_visible(False)
    for contour in originfig.collections:
        contour.set_clip_path(clip)
 
 | 
 
  |