【python利用shp文件进行绘图白化】,大连e都市(python shp文件的读取和绘图)
0evadmin
编程语言
13
文件名:【python利用shp文件进行绘图白化】,大连e都市
【python利用shp文件进行绘图白化】
python白化 白化的作用python实现 白化的作用 参考博文【matlab利用shp文件制作mask白化文件】 python实现 python借助shp文件对绘图进行白化,不需要进行mask文件的制作,可以高效地进行区域绘制 import numpy as npimport cartopy.crs as ccrsimport cartopy.feature as cfimport matplotlib.pyplot as pltimport cartopy.io.shapereader as shpreaderfrom cartopy.mpl.ticker import LatitudeFormatter,LongitudeFormatterfrom matplotlib.path import Pathfrom cartopy.mpl.patch import geos_to_pathplt.rcParams['font.sans-serif']=['KaiTi']shp_path=r'.\省.shp'shp_data=shpreader.Reader(shp_path)fig=plt.figure(figsize=(3,2),dpi=500)ax1=plt.subplot(121,projection=ccrs.PlateCarree())ax2=plt.subplot(122,projection=ccrs.PlateCarree())for i,ax in enumerate([ax1,ax2]):ax.add_geometries(shp_data.geometries(),crs=ccrs.PlateCarree(),edgecolor='k',facecolor='none',lw=0.5)ax.set_extent([70, 140, 0, 55],crs=ccrs.PlateCarree())ax.set_xticks(np.arange(70,140,5))ax.set_yticks(np.arange(0,55,5))# ax.xaxis.set_major_formatter(LongitudeFormatter())# ax.yaxis.set_major_formatter(LatitudeFormatter())ax.tick_params(direction='in',labelsize=3,top=True,right=True,length=2,width=0.5)if i==0:ax.set_title('未白化',fontsize=6)else:ax.set_title('白化后',fontsize=6)########定义绘图数据######################x=np.arange(70, 140, 0.02)y=np.arange(0, 55, 0.02)X,Y=np.meshgrid(x,y)Z=(X-108)**2+(Y-29)**2#######循环画图#########################for i,ax in enumerate([ax1,ax2]):if i==0:ax.contourf(X,Y,Z)else:ac=ax.contourf(X,Y,Z)#######获取path#######################records=shp_data.records()for record in records:if record.attributes["省"] in ["河南省"]:path=Path.make_compound_path(*geos_to_path([record.geometry]))#######白化###########################for collection in ac.collections:collection.set_clip_path(path, transform=ax2.transData)file_nineline = ".\九段线.shp"reader_nineline = shpreader.Reader(file_nineline)ax.add_geometries(reader_nineline.geometries(), crs=ccrs.PlateCarree(), lw=0.5, fc='none')plt.show() 参考:https://mp.weixin.qq.com/s?__biz=MzIxODQxODQ4NQ==&mid=2247484487&idx=1&sn=e654ab7eeeb41a15f816b52b391e93cb&chksm=97eb981da09c110ba06115ed93a4a4450bbe84f8b57b90a9819b6b06f801b533c1b002f14223&scene=21
同类推荐
-

【Python 常用脚本及命令系列 12.1 -- OpenCV 设置图片区域为某个颜色】,tcl s850
查看 -

【Python3】【力扣题】338. 比特位计数,卓越亚马逊图书
查看 -

【Python】AppUI自动化—appium自动化元素定位、元素事件操作(17)下,dv6-6029tx
查看 -

【Python】Flask + MQTT 实现消息订阅发布,ipad3发布
查看 -

【Python】Python元组学习,三星e808
查看 -
![【Python】[02]初识Python,rv770(python rvs)](https://m.0ev.cc/zb_users/cache/thumbs/23e6181118b51d9a0b36fcaeaa9a7ece-80-80-1.jpg)
【Python】[02]初识Python,rv770(python rvs)
查看 -

【Python】上市公司数据进行经典OLS回归实操,花王论坛(python ols回归)
查看 -

【Python】实现excel文档中指定工作表数据的更新操作,摩托罗拉e3
查看 -

【Python】常用的数据类型介绍以及它们之间相互转化,oppo a520
查看
控制面板
网站分类
搜索
最新留言
文章归档
网站收藏
友情链接