社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

完整代码 | Python绘制高原涡、台风移动路径图

happy科研 • 10 月前 • 458 次点击  


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文件

reader = cartopy.io.shapereader.Reader('D:\PAPER\date\qingzhangshp\qingzang.shp')#读取文件

#输入高原涡的经纬度(数据多时,建议直接读文件)

x=np.array([89.05,96.47,99.89,100.08,102.05,105.01,107.49,108.66,110.91,111.46,113.93,114.00,120.00,121.97,122.02,122.97,123.49,124.05,122.99])

y=np.array([36.02,34.99,34.98,34.56,35.00,34.99,35.02,36.66,35.56,36.42,36.00,35.90,36.00,37.00,38.00,39.00,40.00,42.00,42.99])

创建画布

fig=plt.figure(figsize=(20,18))

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

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

img_extent=[leftlon,rightlon,lowerlat,upperlat]

ax=fig.add_axes([0.1,0.1,0.4,0.3],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([89.05,96.47,99.89,100.08,102.05,105.01,107.49,108.66,110.91,111.46,113.93,114.00,120.00,121.97,122.02,122.97,123.49,124.05,122.99])
y=np.array([36.02,34.99,34.98,34.56,35.00,34.99,35.02,36.66,35.56,36.42,36.00,35.90,36.00,37.00,38.00,39.00,40.00,42.00,42.99])


#创建画布
fig=plt.figure(figsize=(20,18))
proj=ccrs.PlateCarree(central_longitude=90)#确定画布的中心经度
leftlon,rightlon,lowerlat,upperlat=(70,140,0,45)#确定画布的经纬度范围
img_extent=[leftlon,rightlon,lowerlat,upperlat]
ax=fig.add_axes([0.1,0.1,0.4,0.3],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()
                                                                   
分享收藏点赞在看



本文编辑:myp

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/158027
 
458 次点击