In [4]:
import pandas as pd
import numpy as np

from bokeh.io import show, output_notebook
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, HoverTool, DatetimeTickFormatter
from collections import OrderedDict   

output_notebook()


BokehJS successfully loaded.

In [5]:
dates = pd.date_range('2014/09/01 00:00', freq='H', periods=24, tz='Europe/Berlin')
data = pd.DataFrame(list(range(0,24)), dates, columns=['hour'])
data['with_tz'] = data.index       
data['no_tz_str'] = [i.strftime('%Y-%m-%d %H:%M:00') for i in data.index]
data.reset_index(inplace=True)
data = data[['hour', 'with_tz', 'no_tz_str']]
data.head()


Out[5]:
hour with_tz no_tz_str
0 0 2014-09-01 00:00:00+02:00 2014-09-01 00:00:00
1 1 2014-09-01 01:00:00+02:00 2014-09-01 01:00:00
2 2 2014-09-01 02:00:00+02:00 2014-09-01 02:00:00
3 3 2014-09-01 03:00:00+02:00 2014-09-01 03:00:00
4 4 2014-09-01 04:00:00+02:00 2014-09-01 04:00:00

In [6]:
# With TZ string
tz_df = data[['hour', 'with_tz']]
tz_df = tz_df.rename(columns={
        'with_tz': 'time',
    })

tz_source = ColumnDataSource(tz_df)
tz_df.head()


Out[6]:
hour time
0 0 2014-09-01 00:00:00+02:00
1 1 2014-09-01 01:00:00+02:00
2 2 2014-09-01 02:00:00+02:00
3 3 2014-09-01 03:00:00+02:00
4 4 2014-09-01 04:00:00+02:00

In [7]:
tz_source.data['time'][0:5]


Out[7]:
[Timestamp('2014-09-01 00:00:00+0200', tz='Europe/Berlin', offset='H'),
 Timestamp('2014-09-01 01:00:00+0200', tz='Europe/Berlin', offset='H'),
 Timestamp('2014-09-01 02:00:00+0200', tz='Europe/Berlin', offset='H'),
 Timestamp('2014-09-01 03:00:00+0200', tz='Europe/Berlin', offset='H'),
 Timestamp('2014-09-01 04:00:00+0200', tz='Europe/Berlin', offset='H')]

In [12]:
pwith = figure(x_axis_type="datetime", tools='', plot_width=900) 
f = ["%d-%b %H:%M %Z"]
pwith.xaxis.formatter = DatetimeTickFormatter(formats={"months": f, "days": f, "hours": f})
pwith.yaxis.axis_label = 'hour'
pwith.xaxis.axis_label = 'timestamp'
pwith.line(x='time', y='hour', source=tz_source, legend='with_tz', color='pink')
show(pwith)


Note the time has automatically been displayed as UTC


In [ ]: