如何绘制netCDF文件中每月数据的箱线图?

时间:2019-06-26 20:11:31

标签: python plot netcdf python-xarray

我一直试图将以下netCDF气候数据绘制成箱线图,但是当我尝试绘制数据时出现TypeError。 因此,我使用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

我该如何格式化月度数据以便产生箱线图?有没有更好的方法来查找月度数据的统计信息?

0 个答案:

没有答案