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. one solution could be to use px.timeline()
like [this] answer. (python - plotly horizontal stacked bar chart not working with x-axis in dates - Stack Overflow)
But i donβt want to use plotly express. How to do this using graph object?