如何在XArray绘图中正确显示datetime64 [ns]时间轴?

时间:2018-07-03 00:21:03

标签: python pandas matplotlib python-xarray

我有一个以这种方式绘制的数据集

a = xr.open_dataset('out.nc').set_index(sSeg = 'reachID')
a.sel(sSeg = 17003601)['IRFroutedRunoff'].plot()
plt.show()

但是,即使时间采用datetime64 [ns]格式,也无法正确绘制时间轴。我该如何绘制时间呢?

enter image description here

数据

print(a ['time])

<xarray.DataArray 'time' (time: 19248)>
array(['2010-06-01T00:00:00.000000000', '2010-06-01T03:00:00.000000000',
       '2010-06-01T06:00:00.000000000', ..., '2016-12-31T15:00:00.000000000',
       '2016-12-31T18:00:00.000000000', '2016-12-31T21:00:00.000000000'], dtype='datetime64[ns]')
Coordinates:
  * time     (time) datetime64[ns] 2010-06-01 2010-06-01T03:00:00 ...
Attributes:
    long_name:  time

打印(a)

<xarray.Dataset>
Dimensions:            (sSeg: 8, sUps: 24, time: 19248)
Coordinates:
  * time               (time) datetime64[ns] 2010-06-01 2010-06-01T03:00:00 ...
  * sSeg               (sSeg) int64 17003601 17003602 17003603 17003604 ...
Dimensions without coordinates: sUps
Data variables:
    reachOrder         (sSeg) int32 ...
    reachList          (sUps) int32 ...
    listStart          (sSeg) int32 ...
    listCount          (sSeg) int32 ...
    basinArea          (sSeg) float64 ...
    upstreamArea       (sSeg) float64 ...
    instBasinRunoff    (time, sSeg) float64 ...
    dlayBasinRunoff    (time, sSeg) float64 ...
    sumUpstreamRunoff  (time, sSeg) float64 ...
    KWTroutedRunoff    (time, sSeg) float64 ...
    UpBasRoutedRunoff  (time, sSeg) float64 ...
    IRFroutedRunoff    (time, sSeg) float64 ...

0 个答案:

没有答案