question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HoverTool does not display datetime

See original GitHub issue

ALL software version info (bokeh, python, notebook, OS, browser, any other relevant packages)

Windows 7 Enterprise python 3.7.2 bokeh 1.0.4 Firefox 65.0.1 / Chrome 71.0.3578.98 both tested

Using bokeh serve

Description of expected behavior and the observed behavior

The tooltip should display a datetime, but instead displays 150TB %. It looks like datetime is first correctly transformed to a unix timestamp, but is then displayed in bytes format instead of datetime. Using {%F} as formatting string displays the full unix timestamp.

The x-axis displays the datetime correctly, so I assume it doesn’t have to do with importing DatetimeTickFormatter.

I followed Configure Plot Tools to implement the tooltip.

Possibly related to this issue on pyviz holoviews

Complete, minimal, self-contained example code that reproduces the issue

from datetime import datetime

from bokeh.models import ColumnDataSource, HoverTool
from bokeh.plotting import figure
from bokeh.io import curdoc

dts = ['19/05/2017 13:39', '20/05/2017 13:34', '21/05/2017 13:28', '22/05/2017 13:27', '23/05/2017 13:12',
       '24/05/2017 13:11', '25/05/2017 13:10', '26/05/2017 11:47', '27/05/2017 11:46', '28/05/2017 11:45',
       '29/05/2017 11:41']
dt = [datetime.strptime(x, '%d/%m/%Y %H:%M') for x in dts]
val = [1.004, 0.915, 0.944, 1.023, 1.075, 0.971, 0.958, 0.969, 1.079, 1.112, 0.999]

source = ColumnDataSource(data={'x': dt, 'y': val})

# @x{%F} doesn't work either
hover_tool = HoverTool(tooltips=[('Timestamp', '@x{%Y%m%d %H:%M}'), ('Value', '@y')],
                       formatters={'Timestamp': 'datetime'},)

plot = figure(title='hover_datetime', x_axis_type='datetime', toolbar_location='above',)
s = plot.scatter(x='x', y='y', source=source)
plot.add_tools(hover_tool)

curdoc().add_root(plot)

Stack traceback and/or browser JavaScript console output

Nothing…

Screenshots or screencasts of the bug in action

image

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
cmdavidson546commented, Jul 31, 2020

@bryevdv I actually need to add ‘@’ before the column name in formatters in order to get this to work for me: formatters={‘@x’: ‘datetime’}

It worked fine once I did that.

0reactions
bryevdvcommented, Feb 28, 2021

@Material-Scientist the key in the formatters dict must match either a column name specification including the @-symbol (e.g. @x) or one of the “special” variables including the $-symbol (e.g $y). It is not the label from the hover tooltip (e.g. “date”) and the reason for this is a label may correspond to several fields or special variables, and it may be desired to format all of them independently.

Also: in the future, please make sure to take “how do I” support-type questions to the Discourse, not the issue tracker:

https://discourse.bokeh.org

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bokeh HoverTool datetime formatter not working
I still get the numeric format of the date as can be seen on the image. I tried formatters={'@x': 'datetime'} with no luck....
Read more >
Datetime Formatting in HoverTool - Bokeh Discourse
The problem is that rather than showing a formatted date the hover tool displays numbers like 1.459e12 which is pretty uninformative.
Read more >
Displaying datetime format in Bokeh hovertools?-Pandas,Python
[Solved]-Displaying datetime format in Bokeh hovertools?- ... %c is the format that specifies the preferred date and time representation for the current ...
Read more >
How to set up HoverTool for multiple columns with hvPlot?
I was trying to add a hovering tooltip to each of the lines plotted ... column is a datetime type but I only...
Read more >
Interactive Data Visualization with Bokeh - Trenton McKinney
Your job is to add a circle glyph that will appear red when the mouse is hovered near the data points. You will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found