I am hoping to plot a graph representing monthly temperature from 1981-01-01 to 2016-12-31.
I would like the months "Jan Feb Mar Apr May...Dec" on the x-axis and the temperature record as the y-axis as my plan is to compare monthly temperature record of 1981 - 1999 with 2000 - 2016.
I have read in the data no problem.
temp1 = xr.open_dataarray('temp1981-1999.nc') temp2 = xr.open_dataarray('temp2000-2016.nc')
and have got rid of the lat and lon dimensions
temp1mean = temp1.mean(dim=['latitude','longitude']) temp2mean = temp2.mean(dim=['latitude','longitude'])
I tried to convert it into a dataframe to allow me to carry on the next step such as averaging the months using group by
temp1.cftime_range(start=None, end=None, periods=None, freq='M', normalize=False, name=None, closed=None, calendar='standard')
t2m time 1981-01-01 276.033295 1981-02-01 278.882935 1981-03-01 282.905579 1981-04-01 289.908936 1981-05-01 294.862457 ... ... 1999-08-01 295.841553 1999-09-01 294.598053 1999-10-01 289.514771 1999-11-01 283.360687 1999-12-01 278.854431
monthly = temp1mean.groupby(temp1mean.index.month).mean()
However I got the following error.
"'DataArray' object has no attribute 'index'"
Therefore, I am wondering if there's any way to groupby all the monthly means and create a graph as followed.
In addition to the main question, I would greatly appreciate if you could also suggest ways to convert the unit kelvin into celsius when plotting the graph. As I have tried the command
celsius = temp1mean.attrs['units'] = 'kelvin'
but the output is merely
"'air_temperature"
I greatly appreciate any suggestion you may have for plotting this grpah! Thank you so so much and if you need any further information please do not hesitate to ask, I will reply as soon as possible.