- 积分
- 2550
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-7-20
- 最后登录
- 1970-1-1
![[二白不哭] 粉丝数:363 微博数:17 新浪微博达人勋](source/plugin/sina_login/img/light.png)
|
发表于 2020-12-18 12:27:21
|
显示全部楼层
from shapely.geometry import Polygon as ShapelyPolygon
from shapely.geometry import Point as ShapelyPoint
import shapefile
cn =m.contour(olon,olat,data_new,levels=levels,colors="k",linewidths=3)
cn_label=plt.clabel(cn,cn.levels,inline=True,fmt="%.1f",fontsize=20)
sf = shapefile.Reader(r'files\CHN_adm1.shp') # note, no suffix, all 3 files are used
recs = sf.records()
shapes = sf.shapes()
for i in range(len(recs)):
if recs[4]=='Fujian':
fj_area=ShapelyPolygon(shapes.points)
break
for text_object in cn_label:
#print (text_object.get_position())
if not fj_area.contains(ShapelyPoint(text_object.get_position())):
text_object.set_visible(False)
############################
把剪裁的地图区域读到polygon 然后判断label的位置是否在地图区域内
如果不是就设置为不可见
|
|