Datetime objects on x axis get added with 6 hours

This seems very simple but I don’t know why it happens. I’m having an x axis as list of datetime objects. When I try to plot it, every elements in the list get added with 6 hours, i.e., datetime.datetime(2018, 8, 14, 1, 0) becomes datetime.datetime(2018, 8, 14, 7, 0).

My code is as followed.

import datetime
import numpy as np
from plotly.offline import plot
import plotly.graph_objs as go

time = [datetime.datetime(2012, 1, 1, 0, 0), datetime.datetime(2012, 1, 1, 1, 0), ... datetime.datetime(2012, 1, 1, 9, 0)]
# => len(time) = 10
y = np.linspace(0, 10, 10)

plot(go.Figure(data = [go.Scatter(x = time, y = y)])

which returns a graph with the first time tick being 2012-01-01 06:00 and the last tick being 2012-01-01 15:00. Any idea why the x axis got interpreted wrongly?

Hi @deedemckay,

I don’t think I’m seeing the same behavior as you are. Here’s what I’m seeing for this example:

import datetime
import numpy as np
from plotly.offline import plot
import plotly.graph_objs as go

time = [datetime.datetime(2012, 1, 1, 0, 0), datetime.datetime(2012, 1, 1, 1, 0), datetime.datetime(2012, 1, 1, 9, 0)]
# => len(time) = 10
y = np.linspace(0, 10, 10)

plot(go.Figure(data = [go.Scatter(x = time, y = y)]))

Here the point location and hover tooltip for the second point appears to be accurate (Jan 1, 2012, at 1am).

What version of plotly.py are you using? I did this test with 3.1.1
-Jon

It’s probable that I’m seeing this error because I’m using plotly 2.7.0. I’ve figured a temporary fix by turning all the datetime objects to strings, tho.

1 Like

Had a similar problem and converting datetime objects to strings worked.