Search code examples
bokehpandas-bokeh

Does Hovertool/tooltip work with pandas df or only with ColumnDataSource


Pretty new to Bokeh. Plotting a barplot (after importing pandas_bokey) works well. But... I want to change the hoover tooltips. Question: should hoover tooltip work with a pandas df in Bokeh or must ColumnDataSource be used? thanks


Solution

  • One option in pandas_bokeh to modify the HoverTool is passing a custom string to hovertool_string.

    import pandas as pd
    import pandas_bokeh
    
    from bokeh.plotting import output_notebook
    output_notebook()
    
    df = pd.DataFrame({'a':[1,2], 'b':[3,4]})
    df.plot_bokeh.bar(hovertool_string=r"""At index @{__x__values}: a is @{a} and b is @{b}""")
    
    default output modified tooltop
    default tooltip modified tooltip

    To see a more complex example check the 2. example in the line plot documentation

    Comment

    Because your question is very open, I am not sure if the answer is satisfying. Please provide some Minimal Working Example and some example data in future.