python最简单的方法画台风路径

文摘   2024-10-06 01:52   德国  

python最简单的方法画台风路径

第一步:

给出数据:

lon =[...];

lat=[...];

#  给入数据,台风坐标,即lon,latlon = [125.5, 124.778, 124.1,123.505,123,122.54,122.2,122.027,121.9,121.598,121.4,121.525,121.8,122.065,122.3,122.415,122.5,122.613,122.8,123.142,123.5,123.715,123.9,124.143,124.4,124.652,124.9];lat = [11.2,11.8154,12.3,12.5798,12.8,13.1575,13.5,13.7448,13.9,13.9426,14,14.2275,14.5,14.6926,14.9,15.2074,15.5,15.6649,15.8,15.9702,16.2,16.5274,16.9,17.2425,17.6,17.99,18.4];

第二步骤:

建立画布画图:

fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())# 建个画布和添加投影方式,因为我们使用地图因此需要像matlab一样给个投影

ax.set_extent([110, 130, 10, 20], crs=ccrs.PlateCarree())# 显示范围:


plt.plot(lon,lat,linestyle='-', color='red', linewidth=2 )

plt.scatter(lon, lat, marker='o', s=20, color='k' )#


最后觉得不好看,就修饰下:和matlab一样,set xtick ytick.

就是语句需要找一找。


还有就是python需要用到的就要先加载那个包,甚至需要先要pip install ....



# load 函数包import numpy as npimport matplotlib.pyplot as pltimport cartopy.crs as ccrsfrom cartopy.mpl.ticker import LongitudeFormatter,LatitudeFormatterimport warningswarnings.filterwarnings('ignore')#  给入数据,台风坐标,即lon,latlon = [125.5, 124.778, 124.1,123.505,123,122.54,122.2,122.027,121.9,121.598,121.4,121.525,121.8,122.065,122.3,122.415,122.5,122.613,122.8,123.142,123.5,123.715,123.9,124.143,124.4,124.652,124.9];lat = [11.2,11.8154,12.3,12.5798,12.8,13.1575,13.5,13.7448,13.9,13.9426,14,14.2275,14.5,14.6926,14.9,15.2074,15.5,15.6649,15.8,15.9702,16.2,16.5274,16.9,17.2425,17.6,17.99,18.4];# 开始画图fig = plt.figure(figsize=(12, 8))ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())# 建个画布和添加投影方式,因为我们使用地图因此需要像matlab一样给个投影ax.set_extent([110, 130, 10, 20], crs=ccrs.PlateCarree())# 显示范围:ax.coastlines(resolution='10m')# 加载地理坐标系统下的全球海陆边界线地图  目前有110m、50m和10max.stock_img()  # 添加地球背景ax.add_feature(cfeature.OCEAN)# 海洋plt.title(f'{2024} Typhoon Track', fontsize=15)plt.plot(lon,lat,linestyle='-', color='red', linewidth=2 )plt.scatter(lon, lat, marker='o', s=20, color='k' )#gl = ax.gridlines(draw_labels=False, linewidth=1, color='k', alpha=0.5, linestyle='--')gl.xlabels_top = gl.ylabels_right = Falseax.set_xticks(np.arange(110, 131, 5))ax.set_yticks(np.arange(10, 21,5))ax.xaxis.set_major_formatter(LongitudeFormatter())ax.xaxis.set_minor_locator(plt.MultipleLocator(1))ax.yaxis.set_major_formatter(LatitudeFormatter())ax.yaxis.set_minor_locator(plt.MultipleLocator(1))ax.tick_params(axis='both', labelsize=10, direction='out')plt.savefig('typhoon_20241.png')plt.show()lon = [154.400000000000,154.045000000000,153.700000000000,153.390000000000,153.200000000000,153.205000000000,153.300000000000,153.425000000000,153.400000000000,152.995000000000,152.500000000000,152.220000000000,152,151.803000000000,151.500000000000,150.930000000000,150.300000000000,149.827000000000,149.400000000000,148.957000000000,148.500000000000,148.008000000000,147.500000000000,147,146.500000000000,145.962000000000,145.500000000000,145.212000000000,145,144.750000000000,144.500000000000,144.257000000000,144,143.700000000000,143.400000000000,143.105000000000,142.900000000000,142.855000000000,142.900000000000,142.913000000000,143,143.197000000000,143.500000000000,143.856000000000,144.300000000000,144.798000000000,145.400000000000,146.099000000000,146.900000000000,147.721000000000,148.700000000000,149.990000000000,151.300000000000,152.207000000000,153.200000000000,154.731000000000,156.500000000000,158.209000000000,160,161.930000000000,164];lat =[10.3000000000000,10.0051000000000,9.80000000000000,9.74750000000000,9.80000000000000,9.91498000000000,10,9.92991000000000,9.80000000000000,9.67022000000000,9.60000000000000,9.61740000000000,9.80000000000000,10.2573000000000,10.7000000000000,10.7877000000000,10.8000000000000,10.9473000000000,11.2000000000000,11.5549000000000,12,12.5074000000000,13,13.3799000000000,13.7000000000000,13.9851000000000,14.3000000000000,14.7348000000000,15.2000000000000,15.5850000000000,16,16.5274000000000,17.1000000000000,17.6800000000000,18.2000000000000,18.5725000000000,18.9000000000000,19.2849000000000,19.7000000000000,20.1199000000000,20.6000000000000,21.2074000000000,21.8000000000000,22.1849000000000,22.6000000000000,23.2547000000000,24,24.6697000000000,25.4000000000000,26.2312000000000,27.2000000000000,28.3367000000000,29.5000000000000,30.4877000000000,31.5000000000000,32.6635000000000,33.9000000000000,35.0719000000000,36.4000000000000,38.0202000000000,39.8000000000000];# 开始画图fig = plt.figure(figsize=(12, 8))ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())# 建个画布和添加投影方式,因为我们使用地图因此需要像matlab一样给个投影ax.set_extent([100, 180, 0, 50], crs=ccrs.PlateCarree())# 显示范围:ax.coastlines(resolution='10m')# 加载地理坐标系统下的全球海陆边界线地图  目前有110m、50m和10max.stock_img()  # 添加地球背景ax.add_feature(cfeature.OCEAN)# 海洋plt.title(f'{2024} Typhoon Track', fontsize=15)plt.plot(lon,lat,linestyle='-', color='k', linewidth=1 )plt.scatter(lon, lat, marker='o', s=20, color='k' )#gl = ax.gridlines(draw_labels=False, linewidth=1, color='k', alpha=0.5, linestyle='--')gl.xlabels_top = gl.ylabels_right = Falseax.set_xticks(np.arange(100, 181, 10))ax.set_yticks(np.arange(0, 51,10))ax.xaxis.set_major_formatter(LongitudeFormatter())ax.xaxis.set_minor_locator(plt.MultipleLocator(1))ax.yaxis.set_major_formatter(LatitudeFormatter())ax.yaxis.set_minor_locator(plt.MultipleLocator(1))ax.tick_params(axis='both', labelsize=10, direction='out')plt.savefig('typhoon_20242.png')plt.show()

参考文章:

https://blog.csdn.net/m0_48405781/article/details/109223403


海洋与大气科学
海洋与大气科学数据分析,数据可视化分享,可教学。
 最新文章