px.timeline Incorrectly interprets x_end datetimes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 18.8k
- Forks
- 2.8k
- Avg merge
- 16h 26m
- Merged PRs (30d)
- 21
Description
The px.timeline function incorrectly generates the end times of the bar traces. The end times are placed before the start times.
Python version 3.8.6
Plotly version 5.4
Steps to reproduce:
import datetime
import plotly.express as px
t0 = datetime.datetime.now()
tf = t0 + datetime.timedelta(hours=1)
px.timeline(x_start=[t0], x_end=[tf])
print(t0)
print(tf)
Produces
2021-11-16 12:21:14.800827 # t0
2021-11-16 13:21:14.800827 # tf
The resulting figure is below. Notice that the right edge of the bar is the same as the start time, but the left edge of the bar is something else entirely.

The behavior is the same when passing a dataframe and column names. If you generate a scatter plot using the same datetime objects, the output works as expected (shown below).

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the px.timeline entry point and reproduce the issue with the datetime values shown in the report, comparing its bar trace coordinates with a scatter plot using the same values. Trace how x_start and x_end are converted into the figure, then verify that the generated bar has the expected start and end times and that the dataframe-and-column-names case also behaves correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100