Python 如何为matplotlib绘图“重置索引”?

Python 如何为matplotlib绘图“重置索引”?,python,pandas,matplotlib,Python,Pandas,Matplotlib,我有以下代码: fig, ax = plt.subplots(1, 1) calls["2016-12-24"].resample("1h").sum().plot(ax=ax) calls["2016-12-25"].resample("1h").sum().plot(ax=ax) calls["2016-12-26"].resample("1h").sum().plot(ax=ax) 这将生成以下图像: 如何使这些线共享x轴?换句话说,我如何使它们不切换日期?如果您不关心使用正确的日期时间

我有以下代码:

fig, ax = plt.subplots(1, 1)
calls["2016-12-24"].resample("1h").sum().plot(ax=ax)
calls["2016-12-25"].resample("1h").sum().plot(ax=ax)
calls["2016-12-26"].resample("1h").sum().plot(ax=ax)
这将生成以下图像:


如何使这些线共享x轴?换句话说,我如何使它们不切换日期?

如果您不关心使用正确的日期时间作为索引,您可以按照您对所有系列的建议重置索引。如果这是你想要实现的,那么它将覆盖所有的时间序列

# the below should
calls["2016-12-24"].resample("1h").sum().reset_index("2016-12-24").plot(ax=ax)
calls["2016-12-25"].resample("1h").sum().reset_index("2016-12-25").plot(ax=ax)
calls["2016-12-26"].resample("1h").sum().reset_index("2016-12-26").plot(ax=ax)
否则,您应该尝试同时对三列重新采样。尝试一下下面的内容,但不知道您的原始数据帧是什么样子,我不确定这是否适合您的情况。您应该发布关于输入数据帧的更多信息

# have a try with the below 
calls[["2016-12-24","2016-12-25","2016-12-26"].resample('1h').sum().plot()

也可以尝试第二种“重置指数”的解决方案,它应该调用完全相同的东西[[2016-12-242016-12-252016-12-26].resample'1h'.sum.reset_index.plotit抱怨即使在添加了缺少的结束括号后,您仍在传递列表。如果不发布正在处理的初始数据帧,这将很困难。可能您应该在调用字段之前重新采样,如下面调用的。resample'1h'‌​[[2016-12-242016-12-252016-12-26].总和重置指数‌​.但再次绘制。我在这里看不见了,我不知道你的索引、列等是什么: