如何在Python中绘制多个时间序列

时间:2018-07-28 12:41:12

标签: python python-2.7 pandas matplotlib

我需要时间序列方面的帮助。我有这个内置在熊猫中的数据框:

          date  bitcoin  tether
91  2017-11-01   0.0444  0.0001
90  2017-11-02   0.0426  0.0000
89  2017-11-03   0.0181  0.0000
88  2017-11-04   0.0296  0.0000
87  2017-11-05   0.0035  0.0000
86  2017-11-06  -0.0582  0.0000
85  2017-11-07   0.0206  0.0000
84  2017-11-08   0.0481  0.0100

我想在同一图中绘制绳索和比特币的运动,时间应该在x轴上显示。 我希望比特币和Tether可以按自己的大小缩放。 我想在图片中使用matplotlib创建类似的东西,但是时间在轴上显示。我不在乎软件包,只在乎结果.....我正在使用Python 2.7。

Tether与比特币Var%

enter image description here

1 个答案:

答案 0 :(得分:3)

这只是标准的plot()

df.set_index(pd.to_datetime(df.date), drop=True).plot()

plot

要添加网格和辅助y轴,请使用plot()参数:

df = df.set_index(pd.to_datetime(df.date), drop=True)
df.bitcoin.plot(grid=True, label="bitcoin", legend=True)
df.tether.plot(secondary_y=True, label="tether", legend=True)

plot2