Why does plotly incorrectly interpret this ISO datetime string?

Viewed 264

The following piece of python code that uses a ISO-formatted date string produces the graph below.

import plotly.express as px
import pandas as pd

bars = pd.DataFrame([{'Task': 'kitter_pick', 'Start': '2020-07-22T23:09:18.221013', 'Finish': '2020-07-22T23:09:25.221013', 'Counter': 2465}])

fig = px.timeline(bars, x_start="Start", x_end="Finish", y="Task",hover_name='Counter')
fig.update_yaxes(autorange="reversed")  # otherwise tasks are listed from the bottom up
fig.show()

result The snippet is similar to https://plotly.com/python/time-series/ from the plotly documentation.

The timescale is completely incorrect due to the finish attribute being incorrectly interpreted by plotly.

When changing the timestrings slightly you obtain the correct result:

bars = pd.DataFrame([{'Task': 'kitter_pick', 'Start': '2020-07-22T23:09:18.221013', 'Finish': '2020-07-22T23:10:25.221013', 'Counter': 2465}])

correct result

Does anybody know why this happens and if there is a way around this?

I have also tried:

  • datetime.datetime objects
  • np.datetime64 objects

Both gave the same results

0 Answers
Related