静态网站做301重定向,咸阳专业学校网站建设,木疙瘩h5官网,贵州网站建设费用python白化 白化的作用python实现 白化的作用
参考博文【matlab利用shp文件制作mask白化文件】
python实现
python借助shp文件对绘图进行白化#xff0c;不需要进行mask文件的制作#xff0c;可以高效地进行区域绘制
import numpy as np
import cartopy.crs as ccrs
impo… python白化 白化的作用python实现 白化的作用
参考博文【matlab利用shp文件制作mask白化文件】
python实现
python借助shp文件对绘图进行白化不需要进行mask文件的制作可以高效地进行区域绘制
import numpy as np
import cartopy.crs as ccrs
import cartopy.feature as cf
import matplotlib.pyplot as plt
import cartopy.io.shapereader as shpreader
from cartopy.mpl.ticker import LatitudeFormatter,LongitudeFormatter
from matplotlib.path import Path
from cartopy.mpl.patch import geos_to_path
plt.rcParams[font.sans-serif][KaiTi]
shp_pathr.\省.shp
shp_datashpreader.Reader(shp_path)
figplt.figure(figsize(3,2),dpi500)
ax1plt.subplot(121,projectionccrs.PlateCarree())
ax2plt.subplot(122,projectionccrs.PlateCarree())
for i,ax in enumerate([ax1,ax2]):ax.add_geometries(shp_data.geometries(),crsccrs.PlateCarree(),edgecolork,facecolornone,lw0.5)ax.set_extent([70, 140, 0, 55],crsccrs.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(directionin,labelsize3,topTrue,rightTrue,length2,width0.5)if i0:ax.set_title(未白化,fontsize6)else:ax.set_title(白化后,fontsize6)
########定义绘图数据######################
xnp.arange(70, 140, 0.02)
ynp.arange(0, 55, 0.02)
X,Ynp.meshgrid(x,y)
Z(X-108)**2(Y-29)**2
#######循环画图#########################
for i,ax in enumerate([ax1,ax2]):if i0:ax.contourf(X,Y,Z)else:acax.contourf(X,Y,Z)
#######获取path#######################
recordsshp_data.records()
for record in records:if record.attributes[省] in [河南省]:pathPath.make_compound_path(*geos_to_path([record.geometry]))
#######白化###########################
for collection in ac.collections:collection.set_clip_path(path, transformax2.transData)file_nineline .\九段线.shp
reader_nineline shpreader.Reader(file_nineline)
ax.add_geometries(reader_nineline.geometries(), crsccrs.PlateCarree(), lw0.5, fcnone)plt.show()参考https://mp.weixin.qq.com/s?__bizMzIxODQxODQ4NQmid2247484487idx1sne654ab7eeeb41a15f816b52b391e93cbchksm97eb981da09c110ba06115ed93a4a4450bbe84f8b57b90a9819b6b06f801b533c1b002f14223scene21