[英]Plotly, Python. Can i plot vertical line based on a datetime object?
我正在預測 Covid 病例並使用 Plotly 進行可視化。 我想 plot 在預測開始的地方畫一條垂直線。 我有一個這樣的圖表。 圖表。 我只想在 2021 年 1 月 25 日的日期為 plot 一條垂直線,因此可以看到預測開始的位置。
因為您沒有共享您的數據,所以我嘗試使用 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/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.