这是我尝试过的代码:
ax = Statements.plot(x='Date', y='mean_Kincaid', legend=True,
title="Fed Statement Kincaid and Sentiment scores over time")
Statements.plot(x='Date', y='mean_Score', ax=ax)
Statements.plot(secondary_y='mean_Kincaid', style='g', ax=ax)
运行时:
ts = Statements.set_index('Date')
ts.mean_Kincaid.plot()
ts.mean_Score.plot(secondary_y=True)
我明白了:
这与我原来的图表有很大不同。造成这种情况的原因是什么?如何解决?
答案 0 :(得分:1)
您正在寻找secondary_y
关键字参数。
ts = Statements.set_index('Date')
ts.mean_Kincaid.plot()
ts.mean_Score.plot(secondary_y=True)
如果您想要显示图例和轴标签,请使用
之类的内容ts = Statements.set_index('Date')
ax = ts.mean_Kincaid.plot(legend=True)
ts.mean_Score.plot(legend=True, secondary_y=True)
ax.set_ylabel('mean_Kincaid')
ax.right_ax.set_ylabel('mean_Score')