Python 在图形上打印两个以上系列(matplotlib plot_date())

Python 在图形上打印两个以上系列(matplotlib plot_date()),python,matplotlib,Python,Matplotlib,我有一个与这里发布的问题类似的问题: 这对我来说很有效,但我想在同一个图上画两个以上的图 例如,在我的例子中,如果我调用plot_date()函数5次,结果图显示最后两次调用的点/线,但在前三次调用中,这些线没有打印,但所有5次都显示在图例中(在5次调用中,我通过不同的颜色和标签区分每个调用) 概述是我正在使用python,打开一个csv文本文件,将数据(序列标签、日期、计数(y))放入元组列表中,然后将该列表放入数据框中。然后我旋转它,将其更改为 df = df.pivot(index='d

我有一个与这里发布的问题类似的问题:

这对我来说很有效,但我想在同一个图上画两个以上的图

例如,在我的例子中,如果我调用plot_date()函数5次,结果图显示最后两次调用的点/线,但在前三次调用中,这些线没有打印,但所有5次都显示在图例中(在5次调用中,我通过不同的颜色和标签区分每个调用)

概述是我正在使用python,打开一个csv文本文件,将数据(序列标签、日期、计数(y))放入元组列表中,然后将该列表放入数据框中。然后我旋转它,将其更改为

df = df.pivot(index='date', columns='series', values='count')
然后我的绘图代码:

fig = plt.figure()
plt.plot_date(x=df.index, y=df['series1'], fmt='bo-', tz=None, xdate=True,
      ydate=False, label="d1", color='red')

plt.plot_date(x=df.index, y=df['series2'], fmt='bo-', tz=None, xdate=True,
      ydate=False, label="d2", color='blue')

plt.plot_date(x=df.index, y=df['series3'], fmt='bo-', tz=None, xdate=True,
      ydate=False, label="d3", color='green')

plt.plot_date(x=df.index, y=df_date_domain['series4'], fmt='bo-', tz=None, xdate=True,
      ydate=False, label="d4", color='orange')

plt.plot_date(x=df.index, y=df_date_domain['series5'], fmt='bo-', tz=None, xdate=True,
      ydate=False, label="d5", color='black')

fig.autofmt_xdate()    
plt.legend()
plt.xlabel("Day")
plt.ylabel("Count")
plt.title("example of trying to plot more than 2 on the same figure")
fname='test.pdf'
plt.savefig(fname)
下面是结果

下面是全文代码,后面是文本输入(python test_plot.py plot_test.csv)

由于文本输入很长,我在pastebin中有它
上面的代码也在这里的pastebin:

,因为数据是相同的。您的线被绘制在彼此的顶部

>>> np.all(df['series1'] == df['series5'])
True
>>> np.all(df['series1'] == df['series3'])
True
>>> np.all(df['series2'] == df['series4'])
True

你能提供一个可运行的示例,用示例数据来演示这个问题吗?@BrenBarn-I添加了代码,以及数据输入和相同代码的pastebin链接。非常感谢你!我在绞尽脑汁。。我改变了数据编号,现在我确实看到了所有绘制的数据:)如果它对任何人都有帮助,我能够迭代列表或索引列表,例如,在我的代码中,对于绘图日期函数
y=df[series\u 2\u extract[0]
>>> np.all(df['series1'] == df['series5'])
True
>>> np.all(df['series1'] == df['series3'])
True
>>> np.all(df['series2'] == df['series4'])
True