如何在时间轴 X 轴上移动绘制的线?
How to move a plotted line on the timeline X axis?
我有这张图
enter image description here
和这段代码:
plt.style.use('ggplot')
plt.plot(df1['Close'], color='b', label='Historical closing price')
plt.plot(df1_30_pred, color='r', label='30 days prediction')
plt.plot(dftoday['Close'],color='g', label='Real closing price for 30 days')
plt.plot([coefficients[0]*x + coefficients[1] for x in range(len(df1_30_pred))],color='orange', label='30 days prediction trend')
# Adding legend, which helps recognizing the curves according to color
plt.legend(loc='upper left')
plt.xticks(np.arange(0, 300, 10),rotation=45)
plt.yticks(np.arange(0, 200, 10))
plt.legend(loc='upper left')
plt.title('AAPL 30 day prediction', fontsize=20)
plt.xlabel("Date", fontsize=18)
plt.ylabel("Closing price $", fontsize=18)
plt.show()
我想移动橙色趋势线将其放在红色图表的顶部,这样它就会在计算的日期之间。
为此,请指定索引 'df1_30_pred'。
如果正如我指出的那样,它不起作用,则提供所有数据(数据帧)。我会尽力解决问题。
plt.plot(df1_30_pred.index, [coefficients[0]*x + coefficients[1] for x in range(len(df1_30_pred))],color='orange', label='30 days prediction trend')
我有这张图
enter image description here
和这段代码:
plt.style.use('ggplot')
plt.plot(df1['Close'], color='b', label='Historical closing price')
plt.plot(df1_30_pred, color='r', label='30 days prediction')
plt.plot(dftoday['Close'],color='g', label='Real closing price for 30 days')
plt.plot([coefficients[0]*x + coefficients[1] for x in range(len(df1_30_pred))],color='orange', label='30 days prediction trend')
# Adding legend, which helps recognizing the curves according to color
plt.legend(loc='upper left')
plt.xticks(np.arange(0, 300, 10),rotation=45)
plt.yticks(np.arange(0, 200, 10))
plt.legend(loc='upper left')
plt.title('AAPL 30 day prediction', fontsize=20)
plt.xlabel("Date", fontsize=18)
plt.ylabel("Closing price $", fontsize=18)
plt.show()
我想移动橙色趋势线将其放在红色图表的顶部,这样它就会在计算的日期之间。
为此,请指定索引 'df1_30_pred'。 如果正如我指出的那样,它不起作用,则提供所有数据(数据帧)。我会尽力解决问题。
plt.plot(df1_30_pred.index, [coefficients[0]*x + coefficients[1] for x in range(len(df1_30_pred))],color='orange', label='30 days prediction trend')