Datetimes on plot are always treated as local time and shifted to UTC
See original GitHub issueDescription
When displaying datetime.datetime
values along the x-axis using x_axis_type = "datetime"
, the values are shifted if the system’s timezone is not UTC.
For example, if you live in UTC-05:00, then all the dates are shifted ahead 5 hours (7am appears at noon).
This happens regardless of the tzinfo
on the datetimes, including for naive datetimes where tzinfo
is None
.
Sample Code
from datetime import datetime
from bokeh.plotting import figure, show
from bokeh.models.sources import ColumnDataSource
from bokeh.models.tools import CrosshairTool, HoverTool
hours = range(24)
datetimes = [datetime.now().replace(hour=h, minute=0, second=0, tzinfo=None) for h in hours]
example = figure(
x_axis_label = 'Date/Time',
x_axis_type = 'datetime',
y_axis_label = 'Expected Hour',
)
example.circle(
x = 'x',
y = 'y',
fill_color = 'blue',
size = 6,
source = ColumnDataSource({
'x': datetimes,
'y': hours,
'time_fmt': [dt.strftime("%H:%M") for dt in datetimes],
}),
)
example.add_tools(CrosshairTool())
example.add_tools(HoverTool(
tooltips = [
("index", "$index"),
("expected time", "@time_fmt"),
],
))
show(example)
Expected Behaviour
I would have expected that naive datetimes are displayed as is.
Actual Behaviour
System, Library, Browser, Version information
I am using Python 3.5.2 (64-bit) with bokeh 0.12.3 and Firefox 50.0 as well as Chrome 54.0.2840.100 (64-bit) on Ubuntu MATE 16.04.1 LTS and on CentOS release 6.8.
bokeh info (Ubuntu):
Python version : 3.5.2 (default, Sep 10 2016, 08:21:44)
IPython version : 5.1.0
Bokeh version : 0.12.3
BokehJS static path : /usr/local/lib/python3.5/dist-packages/bokeh/server/static
bokeh info (CentOS):
Python version : 3.5.2 (default, Nov 24 2016, 13:03:33)
IPython version : Not installed
Bokeh version : 0.12.3
BokehJS static path : /usr/local/lib/python3.5/site-packages/bokeh/server/static
Other notes
You can work around this issue by setting your system timezone to UTC. This is not ideal though.
Issue Analytics
- State:
- Created 7 years ago
- Comments:20 (11 by maintainers)
Top Results From Across the Web
Matplotlib plot_date keeping times in UTC even with custom ...
Matplotlib plot_date keeping times in UTC even with custom Timezone ... I'm using matplotlib to plot data against timestamps in python 2.6. I've...
Read more >How to display "last updated" information in local time?
Datetime values in Bokeh are always assumed to be local time and are ... on plot are always treated as local time and...
Read more >datetime — Basic date and time types — Python 3.11.1 ...
Because naive datetime objects are treated by many datetime methods as local times, it is preferred to use aware datetimes to represent times...
Read more >Back to Basics: UTC and TimeZones in .NET Web Apps
Web apps typically require that dates are stored in time zone agnostic fashion. This means storing DateTime values as UTC, so that you...
Read more >Will you show me examples of changing time zones with ...
If you have not set the TimeZone on a datetime before, then it does not assume UTC to be converted. Setting the TimeZone...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just pushed this change to the linked PR. With this change, the original code now yields:
@mwerezak @gismo2004 any chance you can test the PR out by cloning and building bokeh locally?
Looks like gismo2004 beat me to it.