In my Python script I gather the datetime objects for two time periods via dateutil.parser
like so:
from dateutil import parser
start_date_1 = parser.parse("2010-08-01").date()
end_date_1 = parser.parse("2010-11-05").date()
start_date_2 = parser.parse("2010-11-06").date()
end_date_2 = parser.parse("2010-11-12").date()
When trying to visualize these time periods with plotly.express.timeline
, there is a gap between consecutive and directly adjacent dates (2010-11-05 and 2010-11-06). Is there any way to join these two bars without overlapping the dates?
df = pd.DataFrame([
dict(Task="period_1", Start=start_date_1, Finish=end_date_1, Stack="stack_2"),
dict(Task="period_2", Start=start_date_2, Finish=end_date_2, Stack="stack_2"),
])
fig = px.timeline(df,
x_start="Start",
x_end="Finish",
y="Stack",
color="Task",
hover_name="Task",
opacity=.7,
width=1000)
fig.update_traces(marker_line_width=1.0, opacity=0.95)
fig.update_layout(
barmode="overlay",
xaxis = dict(
automargin=True,
dtick="M1",
tickformat="%Y-%m-%d",
type="date",
showgrid=True,
rangeslider_visible=True),
yaxis = dict(
automargin=True,
visible=False,
autorange="reversed",
showgrid=True),
legend=dict(
title=""))