我正在尝试绘制时间序列数据,但我遇到了一些问题.
我正在使用此代码:
from matplotlib import pyplot as plt
plt.figure('Fig')
plt.plot(data.index,data.Colum,'g', linewidth=2.0,label='Data')
Run Code Online (Sandbox Code Playgroud)
但我不想在缺失值之间插值!
我怎样才能做到这一点?
尽管在SO和Matplotlib的文档中尝试了一些解决方案,我仍然无法禁用Matplotlib在x轴上创建周末日期.
如您所见,它会向x轴添加不在原始Pandas列中的日期.
我正在使用(评论的行不能成功实现我的目标)来绘制我的数据:
fig, ax1 = plt.subplots()
x_axis = df.index.values
ax1.plot(x_axis, df['MP'], color='k')
ax2 = ax1.twinx()
ax2.plot(x_axis, df['R'], color='r')
# plt.xticks(np.arange(len(x_axis)), x_axis)
# fig.autofmt_xdate()
# ax1.fmt_xdata = mdates.DateFormatter('%Y-%m-%d')
fig.tight_layout()
plt.show()
Run Code Online (Sandbox Code Playgroud)
下面是我的Pandas数据框的示例,日期为索引:
2019-01-09 1.007042 2585.898714 4.052480e+09 19.980000 12.07 1
2019-01-10 1.007465 2581.828491 3.704500e+09 19.500000 19.74 1
2019-01-11 1.007154 2588.605258 3.434490e+09 18.190001 18.68 1
2019-01-14 1.008560 2582.151225 3.664450e+09 19.070000 14.27 1
Run Code Online (Sandbox Code Playgroud)
我发现的一些建议包括这里和这里的自定义自动收报机,但是虽然我没有得到错误,但情节缺少我的第二个系列.
有关如何在matplotlib中禁用日期插值的任何建议?