Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HoverTool does not display datetime #8658

Closed
YMRTN opened this issue Feb 15, 2019 · 6 comments
Closed

HoverTool does not display datetime #8658

YMRTN opened this issue Feb 15, 2019 · 6 comments

Comments

@YMRTN
Copy link
Contributor

YMRTN commented Feb 15, 2019

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

@bryevdv
Copy link
Member

bryevdv commented Feb 15, 2019

@YMRTN this is a usage error, the key in the formatter dict should refer to the column name:

 formatters={'x': 'datetime'}

screen shot 2019-02-15 at 09 47 52

@cmdavidson546
Copy link

@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.

@bryevdv
Copy link
Member

bryevdv commented Jul 31, 2020

@cmdavidson546 what I put above used to work, we made it more strict since I posted it

@Material-Scientist
Copy link

Material-Scientist commented Feb 28, 2021

Could you explain how it works now?

The following still doesn't work for me:

p.add_tools(HoverTool(
    tooltips=[
        ("date",  "$x{%F}"),
        ("price", "$y{"+f"0.00"+" a}"),
        ("value", "@image{0,0.00}"),
    ],

    formatters={
        "date"      : "datetime"
    },
))

image

*Edit
Nevermind, the following works:

p.add_tools(HoverTool(
    tooltips=[
        ( "date",  "$x{%F}"            ),
        ( "price", "$y{"+f"0.00"+" a}" ),
        ( "value", "@image{0,0.00}"      ),
    ],

    formatters={
        '$x'      : 'datetime', # use 'datetime' formatter for 'date' field
    },

    # display a tooltip whenever the cursor is vertically in line with a glyph
#     mode='vline'
))

image

@bryevdv
Copy link
Member

bryevdv commented 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

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants