在数据框中绘制多个值带日期的python
我有以下数据帧:在数据框中绘制多个值带日期的python,python,pandas,plot,Python,Pandas,Plot,我有以下数据帧: date high low Sentiment 0 2018-02-01 10288.80 8812.28 -4 1 2018-02-02 9142.28 7796.49 -1 2 2018-02-03 9430.75 8251.63 -2 3 2018-02-04 9334.87 8031.22 7 4 2018-02-05
date high low Sentiment
0 2018-02-01 10288.80 8812.28 -4
1 2018-02-02 9142.28 7796.49 -1
2 2018-02-03 9430.75 8251.63 -2
3 2018-02-04 9334.87 8031.22 7
4 2018-02-05 8364.84 6756.68 -4
5 2018-02-06 7850.70 6048.26 -12
6 2018-02-07 8509.11 7236.79 -11
7 2018-02-08 8558.77 7637.86 -17
8 2018-02-09 8736.98 7884.71 9
9 2018-02-10 9122.55 8295.47 -4
10 2018-02-11 8616.13 7931.10 4
11 2018-02-12 8985.92 8141.43 0
12 2018-02-13 8958.47 8455.41 -3
13 2018-02-14 9518.54 8599.92 -4
我的最终目标是代表所有的价值观从数据框中,但我看不到x轴上的日期。我使用了以下代码:
df = Original_df [['date', 'high', 'low', 'Sentiment']].copy()
ax = df.plot(secondary_y='Sentiment')
ax.set_yscale('linear')
plt.show()
更新:即使这样,我也看不到日期。我做错了什么
df = Original_df[['date', 'high', 'low', 'Sentiment']].copy()
df = df.set_index('date')
ax = df.plot(secondary_y='Sentiment')
ax.set_yscale('linear')
plt.show()
这应该可以做到:
df = df.set_index('date')
ax = df.plot(secondary_y='Sentiment')
如果您希望日期列位于x轴上,则必须将其作为数据帧的索引,请尝试df.set_index'date',inplace=True,然后尝试df.plot…您考虑过如何放置df.plotlabel='date'吗?谢谢您的帮助,但需要设置所需的值不要appear@PabloPicciau对不起,我想说的是df.plotx='date,y='high',但我想你需要3个plots。我看到的不是数字,而是日期这个词