如何阻止matplotlib显示额外的年份或月份?

2024-09-29 00:18:20 发布

您现在位置:Python中文网/ 问答频道 /正文

例如,我有一个数组:

ncdf1['level'].loc['2017':'2017']

<xarray.DataArray 'level' (time: 246)>
array([302.52 , 302.42 , 302.3  , ..., 310.07 , 310.74 , 309.723])
Coordinates:
  * time     (time) datetime64[ns] 2017-01-01 2017-01-02 ... 2017-12-21

但当我尝试绘制它时,我会得到额外的一个月(如果尝试了多年,则为一年):

ncdat['level'].loc['2017':'2017'].plot(color='#1f78b4')

我怎样才能从1月到12月自动生成绘图

y

#你知道吗

ncdat

<xarray.Dataset>
Dimensions:  (time: 4680)
Coordinates:
  * time     (time) datetime64[ns] 2005-01-01 2005-01-02 ... 2019-05-09
Data variables:
    level    (time) float64 307.7 307.4 307.2 307.0 ... 300.4 301.3 303.2 303.0
    storage  (time) float64 0.02 0.02 0.02 0.02 0.02 ... 0.001 0.001 0.007 0.006

Tags: time绘制数组levelarraylocxarrayns