第八星系人气爱 发表于 2024-2-29 20:48:04

Python--高原涡或台风移动路径图


作者:第八星系-欣妹儿
邮箱:3035245582@qq.com

引入库函数
import numpy as np
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.io.shapereader import Reader
import cartopy.feature as cfeature
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
from cartopy.io.shapereader import Reader
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import cartopy.mpl.ticker as cticker
import cartopy.io.shapereader as shpreader定义路径图背景
def contour_map(fig,img_extent,spec):fig.set_extent(img_extent,crs=ccrs.PlateCarree())    fig.add_feature(cfeature.COASTLINE.with_scale('50m'))#添加海岸线    fig.add_feature(cfeature.LAKES,alpha=0.5)#添加湖泊,并调整透明度

#fig.add_feature(cfeature.LAND)    fig.set_xticks(np.arange(leftlon,rightlon+spec,spec),crs=ccrs.PlateCarree())#设置X轴刻度及间隔    fig.set_yticks(np.arange(lowerlat,upperlat+spec,spec),crs=ccrs.PlateCarree())#设置Y轴刻度及间隔    lon_formatter=cticker.LongitudeFormatter()    lat_formatter=cticker.LatitudeFormatter()    fig.xaxis.set_major_formatter(lon_formatter)

fig.yaxis.set_major_formatter(lat_formatter)读取青藏高原shp文件
def contour_map(fig,img_extent,spec):fig.set_extent(img_extent,crs=ccrs.PlateCarree())    fig.add_feature(cfeature.COASTLINE.with_scale('50m'))#添加海岸线    fig.add_feature(cfeature.LAKES,alpha=0.5)#添加湖泊,并调整透明度

#fig.add_feature(cfeature.LAND)    fig.set_xticks(np.arange(leftlon,rightlon+spec,spec),crs=ccrs.PlateCarree())#设置X轴刻度及间隔    fig.set_yticks(np.arange(lowerlat,upperlat+spec,spec),crs=ccrs.PlateCarree())#设置Y轴刻度及间隔    lon_formatter=cticker.LongitudeFormatter()    lat_formatter=cticker.LatitudeFormatter()    fig.xaxis.set_major_formatter(lon_formatter)

fig.yaxis.set_major_formatter(lat_formatter)创建画布
fig=plt.figure(figsize=(20,18))

proj=ccrs.PlateCarree(central_longitude=90)#确定画布的中心经度

leftlon,rightlon,lowerlat,upperlat=(70,140,0,45)#确定画布的经纬度范围

img_extent=

ax=fig.add_axes(,projection=proj)

contour_map(ax,img_extent,10)标记处青藏高原的范围
provinces = cartopy.feature.ShapelyFeature(reader.geometries(),crs=ccrs.PlateCarree(),edgecolor='k',facecolor='w',alpha=0.4)#调整边界颜色,填充颜色及透明度

ax.add_feature(provinces, linewidth=0.9, zorder=2)#调整线宽

ax.plot(x1,y1,linewidth=2,transform=ccrs.PlateCarree())#画出高原涡的轨迹线

ax.scatter(x1,y1,transform=ccrs.PlateCarree())#将不同时刻高原涡的位置打点

plt.savefig('road2.png',dpi=500)#设置图片保存位置、格式、精度

plt.show()


完整代码
#轨迹图
#引入库函数
import numpy as np
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.io.shapereader import Reader
import cartopy.feature as cfeature
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
from cartopy.io.shapereader import Reader
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import cartopy.mpl.ticker as cticker
import cartopy.io.shapereader as shpreader

def contour_map(fig,img_extent,spec):
    fig.set_extent(img_extent,crs=ccrs.PlateCarree())
    fig.add_feature(cfeature.COASTLINE.with_scale('50m'))#添加海岸线
    fig.add_feature(cfeature.LAKES,alpha=0.5)#添加湖泊,并调整透明度
    #fig.add_feature(cfeature.LAND)

    fig.set_xticks(np.arange(leftlon,rightlon+spec,spec),crs=ccrs.PlateCarree())#设置X轴刻度及间隔
    fig.set_yticks(np.arange(lowerlat,upperlat+spec,spec),crs=ccrs.PlateCarree())#设置Y轴刻度及间隔
    lon_formatter=cticker.LongitudeFormatter()
    lat_formatter=cticker.LatitudeFormatter()
    fig.xaxis.set_major_formatter(lon_formatter)
    fig.yaxis.set_major_formatter(lat_formatter)

#读取青藏高原shp文件
reader = cartopy.io.shapereader.Reader('D:\PAPER\date\qingzhangshp\qingzang.shp')#读取文件
#输入高原涡的经纬度(数据多时,建议直接读文件)
x=np.array()
y=np.array()


#创建画布
fig=plt.figure(figsize=(20,18))
proj=ccrs.PlateCarree(central_longitude=90)#确定画布的中心经度
leftlon,rightlon,lowerlat,upperlat=(70,140,0,45)#确定画布的经纬度范围
img_extent=
ax=fig.add_axes(,projection=proj)
contour_map(ax,img_extent,10)


#标记出青藏高原的范围
provinces = cartopy.feature.ShapelyFeature(reader.geometries(),crs=ccrs.PlateCarree(),edgecolor='k',facecolor='w',alpha=0.4)#调整边界颜色,填充颜色及透明度
ax.add_feature(provinces, linewidth=0.9, zorder=2)#调整线宽
ax.plot(x1,y1,linewidth=2,transform=ccrs.PlateCarree())#画出高原涡的轨迹线
ax.scatter(x1,y1,transform=ccrs.PlateCarree())#将不同时刻高原涡的位置打点

plt.savefig('road2.png',dpi=500)#设置图片保存位置、格式、精度
plt.show()

微信搜索“第八星系人造大气理论爱好者”公众号,关注获取文章数据

页: [1]
查看完整版本: Python--高原涡或台风移动路径图