Closed Blissful-Jasper closed 2 months ago
Thanks for opening your first issue here at xarray! Be sure to follow the issue template! If you have an idea for a solution, we would really welcome a Pull Request with proposed changes. See the Contributing Guide for more. It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better. Thank you!
this is my solution:
import pandas as pd
converted_times = [pd.Timestamp(t.strftime("%Y-%m-%d %H:%M:%S")) for t in tas.time.values]
#
print(converted_times)
tas['time'] = converted_times
tas.sel(time=slice('1871-01','1876-12')).sel(lat=28, lon=118, method='nearest').plot(size=6)
please install nc-time-axis
in your environment, that is our recommended solution.
from their environment dump it looks like nc-time-axis=1.4.1
is installed but not detected. So I guess I'd try calling
import nc_time_axis
to see if that raises an ImportError
. If so, that would be a broken environment, and you might have luck recreating it (though not sure). If not I have no idea, but in that case I'd recommend opening an issue on the nc-time-axis
repository.
What is your issue?
Hi,all When I use xarray to process Netcdf file from cmip6, I find that I can't plot the time series of a point with the error: Plotting of arrays of cftime.datetime objects or arrays indexed by cftime.datetime objects requires the optional
nc-time-axis
(v1.2.0 or later) package.My question is: Is this caused by the xarray related matplotlib library not being compatible with changing the time type of the file, or is it something else. The solution that comes to mind here is to manually replace its time type with a recognizable one, is there another easier solution?
The time type of this nc file is
this test file is here :
tas_Amon_CESM2-WACCM_historical_r1i1p1f1_gn_185001-201412.nc
test code:
my package version: