情节上,Python。我可以根据日期时间对象绘制垂直线吗?
Plotly, Python. Can i plot vertical line based on a datetime object?
我正在预测 Covid 病例并使用 Plotly 进行可视化。我想在预测开始的地方绘制一条垂直直线。我有一个这样的图表。
chart。我只想在 2021 年 1 月 25 日绘制一条垂直线,以便在预测开始的位置可见。
因为您没有分享您的数据,所以我尝试使用来自 plotly 的示例代码片段来解决这个问题:
import plotly.express as px
df = px.data.stocks()
fig = px.line(df, x='date', y="GOOG")
fig.add_vline(x='2019-01-25')
fig.show()
我在 fig.show() 之前的代码中添加了以下行:
fig.add_vline(x='2021-01-25')
如果我的日期格式与您的不同,您可以通过打印图形输入来获取:
print(df)
date ...
0 2018-01-01 ...
1 2018-01-08 ...
2 2018-01-15 ...
3 2018-01-22 ...
4 2018-01-29 ...
... ...
如果您需要更多信息和示例,请查看:https://plotly.com/python/horizontal-vertical-shapes/
My result chart
我正在预测 Covid 病例并使用 Plotly 进行可视化。我想在预测开始的地方绘制一条垂直直线。我有一个这样的图表。 chart。我只想在 2021 年 1 月 25 日绘制一条垂直线,以便在预测开始的位置可见。
因为您没有分享您的数据,所以我尝试使用来自 plotly 的示例代码片段来解决这个问题:
import plotly.express as px
df = px.data.stocks()
fig = px.line(df, x='date', y="GOOG")
fig.add_vline(x='2019-01-25')
fig.show()
我在 fig.show() 之前的代码中添加了以下行:
fig.add_vline(x='2021-01-25')
如果我的日期格式与您的不同,您可以通过打印图形输入来获取:
print(df)
date ...
0 2018-01-01 ...
1 2018-01-08 ...
2 2018-01-15 ...
3 2018-01-22 ...
4 2018-01-29 ...
... ...
如果您需要更多信息和示例,请查看:https://plotly.com/python/horizontal-vertical-shapes/
My result chart