-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
@actioncrypto
Description
Hello,
This is a code snippet that shows how even when explicitly defining timezones, and stripping out any possible confusion, plot.ly will refuse to display the X axis in the local timezone, instead converting and showing UTC only.
My working code is slightly different, but the incorrect end behavior is the same in this case as well when originating from strings and simple DataFrames
inspecting the fig immediately before being called to draw graph indeed shows the correct US/Eastern timezone, which happens as expected when the x value of the trace is defined.
import plotly.plotly as py from plotly.graph_objs import * import pandas as pd import sys, datetime from datetime import timedelta incoming = { 7887966: [0.601345, 152.21, 253.12, '2015-04-04 19:31:30'], 7887967: [0.075392, 19.08, 253.12, '2015-04-04 19:31:34'], 7887968: [0.385279, 97.39, 252.77, '2015-04-04 19:32:13'], 7887969: [0.330650, 83.69, 253.12, '2015-04-04 19:32:14'], 7887970: [0.110700, 28.02, 253.13, '2015-04-04 19:32:14']} df = pd.DataFrame.from_dict(incoming, orient='index') df.columns = ['a','b','y','time'] df['time'] = pd.to_datetime(df['time']) df = df.set_index('time') trace = Box( x=df.index.tz_localize('UTC').tz_convert('US/Eastern'), y=df['y'].values, name='timezone issues', fillcolor='#a5b404', opacity=0.66, marker=Marker( color='#a5b404' ) ) data = Data([trace]) axis_style = dict( zeroline=True, zerolinecolor='#444', zerolinewidth=1, gridcolor='#eee', autotick=True, showline=False ) layout = Layout( title='Timezone offset issue', plot_bgcolor='#fff', hovermode='closest', autosize=True, height=610, width=1296, showlegend=False, xaxis=XAxis( axis_style, autorange=True, rangemode='normal', tickangle='auto', title='Time (note the UTC, when should be US Eastern)', ), yaxis=YAxis( axis_style, title='Y axis (no issues here)' ) ) fig = Figure(data=data, layout=layout) py.plot(fig, filename='timezone-issues', world_readable=False)
Metadata
Metadata
Assignees
Labels
No labels