如何在时间轴X轴上移动绘制线?

发布于 2025-01-19 22:36:41 字数 906 浏览 1 评论 0原文

我有此图

在此处输入图像描述

和此代码:

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()

我想移动橙色趋势线将其放在红色图的顶部,以便在日期之间进行计算。

I have this graph

enter image description here

and this code:

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 
quot;, fontsize=18)
plt.show()

I want to move the orange trend line to place it on top of the red graph, so it will be between the dates is calculated for.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林迷了鹿 2025-01-26 22:36:41

为此,请指定索引“ 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')

To do this, specify the indexes 'df1_30_pred'.
If, as I indicated, it does not work, then give all the data(dataframe). I'll try to solve the problem.

 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')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文