holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 402 forks source link

Bokeh HoverTool text field not showing up when column name contains space #4501

Open horatiubota opened 4 years ago

horatiubota commented 4 years ago

ALL software version info

pandas 1.0.5 bokeh 2.1.1 holoviews 1.13.2 hvplot 0.5.2 (imported with import hvplot.pandas) jupyterlab 2.1.5 (lab extensions are up to date)

Chrome 83, macOS Catalina

Description of expected behavior and the observed behavior

Text field in tooltip not showing up (i.e., shown as ???) when there is a space in the column name. This does not happen when plotting with bokeh directly, and does not happen when there is no space in the column name. Also, this does not happen if the column contains numerical values (not text).

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

import bokeh
import holoviews as hv
import hvplot.pandas

from bokeh.models import HoverTool
from bokeh.sampledata.periodic_table import elements

elements = elements.dropna(how='any').copy()

tooltips = [
    ('boiling point', '@{boiling point}{0,0.00}'),
    ('melting point', '@{melting point}{0,0.00}'),
    ('standard state', '@{standard state}'),
]
hover = HoverTool(tooltips=tooltips)

###
### with bokeh
###

plot = bokeh.plotting.figure(width=600, height=300, tools=[hover])
plot.scatter(source=elements, x='boiling point', y='melting point')

bokeh.plotting.show(plot)

image

###
### with holoviews
###

points = hv.Points(
    elements, ['boiling point', 'melting point'],
    ['year discovered', 'standard state']
)

points.opts(
    width=600, height=300,
    tools=[hover],
    line_color='black'
)

image

###
### with hvplot
###

elements.hvplot(
    kind='scatter',
    x='boiling point', 
    y='melting point',
    hover_cols=['year discovered', 'standard state'],
).opts(tools=[hover])

image

Renaming the text column from standard state to standard_state fixes the problem:

###
### rename "standard state" column to "standard_state"
###

elements = elements.rename(columns={'standard state': 'standard_state'})

tooltips = [
    ('boiling point', '@{boiling point}{0,0.00}'),
    ('melting point', '@{melting point}{0,0.00}'),
    ('standard state', '@{standard_state}'),
]
hover = HoverTool(tooltips=tooltips)

points = hv.Points(
    elements, ['boiling point', 'melting point'],
    ['year discovered', 'standard_state']
)

points.opts(
    width=600, height=300,
    tools=[hover],
    line_color='black'
)

image

jlstevens commented 4 years ago

Thanks for reporting this! I've reproduced the problem with the latest release of HoloViews and Bokeh.

It is pretty bizarre that the float columns 'boiling point' and 'melting point' are fine with the space but the behavior of 'standard state' (string values presumably) does. Definitely looks like a bug to me.

ruoyu0088 commented 4 years ago

to check the columns created by holoviews:

from bokeh.sampledata.periodic_table import elements
from bokeh.models import HoverTool

elements = elements.dropna(how='any').copy()

tooltips = [
    ('boiling point', '@{boiling point}{0,0.00}'),
    ('melting point', '@{melting point}{0,0.00}'),
    ('standard state', '@{standard state}'),
]
hover = HoverTool(tooltips=tooltips)

points = hv.Points(
    elements, ['boiling point', 'melting point'],
    ['year discovered', 'standard state']
)

p = points.opts(
    width=600, height=300,
    tools=[hover],
    line_color='black'
)

render = hv.renderer('bokeh')
pp = render.get_plot(p)
from bokeh.models import ColumnDataSource
source = plot.root.select_one(ColumnDataSource)
source.data.keys()

the output is

dict_keys(['boiling point', 'melting point', 'boiling_point', 'melting_point', 'year_discovered', 'standard_state'])

and the columns with underscore is created by the line:

dim = util.dimension_sanitizer(d.name)

in

https://github.com/holoviz/holoviews/blob/0a8a19c1bf53bdc7089f5f0472f2dd1ad17f1c45/holoviews/plotting/bokeh/element.py#L287