[英]Horizontal bar plotly with datetime
I wanted to create a timeline graph with horizontal bar.我想创建一个带有水平条的时间线图。 I tried the following code:
我尝试了以下代码:
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Bar(
y=['AndOn'],
x=["22-07-01 00:00:8"],
name='SF Zoo',
orientation='h',
legendgroup="group1",
marker=dict(
color='rgba(246, 78, 139, 0.6)',
line=dict(color='rgba(246, 78, 139, 1.0)', width=1)
)
))
fig.add_trace(go.Bar(
y=['AndOn'],
x=["22-07-01 00:00:18"],
name='LA Zoo',
legendgroup="group2",
orientation='h',
marker=dict(
color='rgba(58, 71, 80, 0.6)',
line=dict(color='rgba(58, 71, 80, 1.0)', width=1)
)
))
fig.add_trace(go.Bar(
y=['AndOn'],
x=["22-07-01 00:00:5"],
name='SF Zoo',
legendgroup="group1",
orientation='h',
marker=dict(
color='rgba(246, 78, 139, 0.6)',
line=dict(color='rgba(246, 78, 139, 1.0)', width=1)
)
))
fig.update_layout(barmode='stack')
fig.show()
The date time in x axis is not showing correct. x 轴上的日期时间显示不正确。 one solution could be to use px.timeline() like [this] answer.
一种解决方案可能是使用 px.timeline() 之类的[this]答案。 But i don't want to use plotly express.
但我不想使用 plotly 快递。 How to do this using graph object?
如何使用图形 object 执行此操作? Also i don't want to use deprecated figure factory
我也不想使用已弃用的图形工厂
I think this is bug in Bar graph.我认为这是条形图中的错误。 It gets confused with date in y axis (or x in case of horizontal bar).
它与 y 轴上的日期(或在水平条的情况下为 x)混淆。 Anyway, i solved this by using scatterplot.
无论如何,我通过使用散点图解决了这个问题。
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(y=[0,0],x=["2022-07-15 12:00:08","2022-07-15 12:00:18"],mode="lines",line=dict(color="red",width=100)))
fig.add_trace(go.Scatter(y=[0,0],x=["2022-07-15 12:00:18","2022-07-15 12:00:22"],mode="lines",line=dict(color="green",width=100)))
fig.add_trace(go.Scatter(y=[0,0],x=["2022-07-15 12:00:22","2022-07-15 12:00:25"],mode="lines",showlegend=False,line=dict(color="red",width=100)))
fig.update_layout(yaxis_range=[0,0])
fig.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.