plotly.py
plotly.py copied to clipboard
px.timeline Incorrectly interprets x_end datetimes
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).
I tried to create a timeline plot manually by using the go.Bar trace, and I got the same problem with the same erroneous end date. So I think this is an issue with the Bar trace rather than px.timeline.
Can you tell me a bit about how you're running things? like in a VSCode notebook Jupyter Notebook or Jupyter Lab or...? Which version of Plotly.py are you using?
With the latest version of Plotly.py in JupyterLab 3.0 this is not an issue, but if somehow your environment has an older version of the Javascript library loaded I can imagine this behaviour occurring. Here's what I see when I run this code:
Thanks for the reply. I am indeed running through VSCode, though just executing a .py file in an interactive window. That's interesting. If I write the file and open it in a browser, it works as expected. But if I view that file in an interactive window (the same interactive window that wrote the good file) it's broken. This all held true when I tried it on another computer, too. So is this a Jupyter/JS problem like you said?
My Jupyter extension version is 2021.8.2041215044 and my VS Code version is 1.60.1. Are there any other version numbers I can provide before I try some updates? Anything else I can do on my end to help out?
Have there been any updates on this? I run into the same problem using an Azure Synapse notebook.
same issue