import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset
# 读取 nc 文件
nc_file = "2010_air_12.nc"
nc_data = Dataset(nc_file, "r")
# 获取经度、纬度、时间和温度数据
lon = nc_data.variables["longitude"][:]
lat = nc_data.variables["latitude"][:]
time = nc_data.variables["time"][:]
temp = nc_data.variables["t"][:]
level = nc_data.variables["level"][:]
# 找到对应时间索引(假设时间是按小时存储的)
# 6月25日12:00对应的时间索引为 176
desired_time_index = 176
# 找到对应经度范围索引
desired_lon_indices = np.where((lon >= 70) & (lon <= 140))[0]
# 选择对应时间和经度范围的温度数据
desired_temp = temp[desired_time_index, :, :, desired_lon_indices]
# 绘制温度剖面填色图
plt.imshow(desired_temp[0, :, :], extent=[lat[0], lat[-1], level[0], level[-1]], aspect='auto',cmap='jet')
plt.colorbar(label='Temperature')
plt.xlabel('Latitude')
plt.ylabel('Altitude')
plt.title('xyplot5_python-1')
plt.savefig("xyplot5_python-1.png")
plt.show()
读取nc文件,绘制6月25日12:00,东经70-140度间平均温度剖面填色图,横坐标为纬度,纵坐标为高度。