import netCDF4 as nc
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from matplotlib.patches import Rectangle, Circle
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
import os
import matplotlib
matplotlib.use('TkAgg')
# 打开 NetCDF 文件 替换为自己的保存路径
dataset = nc.Dataset('C:/Users/Mayn/Desktop/ 台 风 实 验 / 台 风 实 验
/mean_sea_level_pressure.nc', 'r')
# 读取海平面气压数据
seapress = dataset.variables['msl'][:]
seapress = seapress / 100 # 转换为百帕
# 提取经度和纬度信息
lons = dataset.variables['longitude'][:]
lats = dataset.variables['latitude'][:]
# 提取时间变量
times = dataset.variables['time'][:]
time_units = dataset.variables['time'].units
calendar = dataset.variables['time'].calendar if hasattr(dataset.variables['time'], 'calendar') else
'standard'
time_vals = nc.num2date(times, units=time_units, calendar=calendar)
# 读取天气图标 替换为自己的保存路径
weather_icon_path = 'C:/Users/Mayn/Desktop/台风实验/台风实验/panel.png'
icon_img = plt.imread(weather_icon_path)
icon_zoom = 0.030
rect_width = 14
rect_height = 2.5
line_color = (68 / 255, 65 / 255, 65 / 255, 0.84)
# 确保目录存在 替换为自己的保存路径
save_dir = 'C:/Users/Mayn/Desktop/台风实验/台风实验/image'
if not os.path.exists(save_dir):
os.makedirs(save_dir)