熊猫的日期在月初被错误地绘制

Sam*_*dis 9 python matplotlib pandas

我在Pandas有一个时间序列,日期是在月末:

import pandas as pd
s = pd.Series({
    '2018-04-30':     0,
    '2018-05-31':     1,
    '2018-06-30':     0,
    '2018-07-31':    1,
    '2018-08-31':    0,
    '2018-09-30':    1,
})
s.index = pd.to_datetime(s.index)
Run Code Online (Sandbox Code Playgroud)

当我用matplotlib绘制这个时,我会得到我期望的结果,月末的点数和2018年5月之前的行:

import matplotlib.pyplot as plt
plt.plot(s)
Run Code Online (Sandbox Code Playgroud)

Matplotlib图

但是熊猫本土的情节函数在月初绘制了积分:

s.plot()
Run Code Online (Sandbox Code Playgroud)

熊猫图

我想也许这只是熊猫将"4月30日"标记为"四月",但情况似乎并非如此:

s2 = pd.Series([0.2, 0.7], index=pd.date_range('2018-05-01', '2018-05-02'))
s.plot()
s2.plot()
Run Code Online (Sandbox Code Playgroud)

与第一个月的熊猫情节也作图

这是Pandas的一个错误还是我在这里做错了什么?

Imp*_*est 2

这似乎是熊猫的一个错误。要获得与 matplotlib 相同的效果,您可以始终使用x_compat=True. 这也将允许使用matplotlib.dates格式化程序和定位器。

s = pandas.Series(...)
s.plot(x_compat=True)
Run Code Online (Sandbox Code Playgroud)