'Errorbars for NetCDF datasets

My data is in NetCDF format. I have created a time series for my data for lake surface water temperature and chlorophyll-a. I want to use standard deviation as an error bar for my time series data. I am facing a problem with the coding of error bars. The following is my code. Please help.

'''

f = '/Users/shrut/Desktop/shruti /Study_Twente/Thesis data/data/temp/ESACCI-LAKES-L3S-LK_PRODUCTS-MERGED_20000101-20101231_Naivasha.nc'
ds = xr.open_dataset(f)
ds

temp=ds['lake_surface_water_temperature']
temp

chla=ds['chla_mean']
chla

rt=temp.resample(time='M').mean()
rt

ct=chla.resample(time='M').mean()
ct

fig = plt.figure(figsize=(15,10))
rt.mean(axis=(1,2)).plot(marker='.',color='indianred',linestyle='solid',label='LSWT')
ax = fig.gca()
ax.set_ylim([290, 300])
ax2 = ax.twinx()
ct.mean(axis=(1,2)).plot(marker='X', color='forestgreen', linestyle='solid',label='Chla', ax=ax2)
ax2.set_ylim([10,250])
fig.legend()
#For error bars
t=temp.resample(time='M')
t
ds=temp.resample(time='M').mean()
tem=ds.mean(axis=(1,2))
#tem
tds=temp.resample(time='M').std()
tsd=tds.std(axis=(1,2))
#tsd
plt.errorbar(t, tem, xerr = tsd, fmt = 'o',ecolor = 'lightblue',color='m')
'''


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source