如何从netCDF文件绘制月度数据的箱线图?

2024-04-25 14:34:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试将以下netCDF气候数据绘制为方框图,但在尝试绘制数据时出现类型错误。 所以我用xarray读取文件。该文件包含全局模型数据,因此我选择感兴趣的区域(格陵兰岛周围)的坐标。我认为要提取有问题的变量,使用“groupby”方法按月份对数据进行分组(模型包含2年的每日数据)。你知道吗

import matplotlib.pyplot as plt 
import xarray as xr

#read in the files

data_1 = xr.open_dataset('UM_data_Leeds/ubj555_2/SW_down_clean_clear_surf/merged.nc')

#months

months = (data_1.time.dt.month)

#select region in question: Greenland

Greenland_ccs = data_1.where((-56 < data_1.Longitude) & (data_1.Longitude < 12) & (58 < data_1.Latitude) & (data_1.Latitude < 81), drop=True)

#extract the variable in question

GL_SWD_ccs = Greenland_ccs.SW_down_clean_clear_surf.dropna(dim='time')

#group by month

GL_SWD_ccs_monthly = GL_SWD_ccs.groupby('time.month')

#plot as boxplot

plt.boxplot(GL_SWD_ccs_monthly)

当我尝试绘制月份数据时,出现以下错误消息:

TypeError: GroupBy objects only support binary ops when the other argument is a Dataset or DataArray

如何格式化月度数据,以便生成箱线图?有没有更好的方法来寻找月度数据的统计数据?你知道吗


Tags: 文件the数据indatatimeas错误

热门问题