Bokeh data tooltips do not show data showing '???' instead

I am trying to create a complex histogram using Bokeh. I would like to use the hover function, displaying the corresponding data in each part of the panel, but instead of the data, Bokeh shows "???".

I got the data in an excel file called "Sample Worksheet" in a worksheet called "Sales." The sheet is as follows:

Year Category Sales 2016 A 1 2016 B 1 2016 C 1.5 2017 A 2 2017 B 3 2017 C 1 2018 A 2.5 2018 B 3 2018 C 2 

I tried running the following code:

 import numpy as np import scipy as sp from bokeh.charts import Bar, output_file, show from bokeh.models import HoverTool import pandas as pd x = pd.read_excel('Example worksheet.xlsx', 'Sales') bar = Bar(x, label = 'Year', values = 'Sales', agg = 'sum', stack = 'Category', tools='hover') hover = bar.select(dict(type=HoverTool)) source = x hover.tooltips = [('Category', '@Category'),('Sales', '@Sales')] output_file("Expected Sales.html") show(bar) 

After starting, I get the following message in the Python console (I don't think this is related to the theme, but I do it anyway):

 (process:4789): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed 

And then in the browser I get the following diagram:

Folded bar graph

As you can see, the data is replaced by question marks. I got this result for both FF 41.0.1 and Chromium 45.0.2454.101, running on Ubuntu 15.04 (64-bit).

I read the Bokeh tutorial http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html#hovertool , but it does not apply to histograms. I also found this on Stackoverflow: The Bokeh hover tooltip doesn't display all the data - Ipython laptop . The question may be related, but to be honest, I did not quite understand the answer.

+5
source share
2 answers

I had the same problem. I found this link helpful. The prompt for Sales will use the generic @height , for example: hover.tooltips = [('Sales', '@height')]

Similarly, replacing @height with @y will give you total sales for each year. I did not understand how to use the tooltip to access paginated categories or how to use the ColumnData column source mentioned in the link.

+4
source

I was able to recreate your problem and found a solution. First, rest your DF:

 data = [k.split() for k in '''2016 A 1 2016 B 1 2016 C 1.5 2017 A 2 2017 B 3 2017 C 1 2018 A 2.5 2018 B 3 2018 C 2'''.split('\n')] x = pd.DataFrame(data, columns = ['year','category','sales']) x['year'] = x['year'].astype(object) x['sales'] = x['sales'].astype(float) 

Now the solution:

 from bokeh.charts import Bar, output_file, show from bokeh.models import HoverTool from bokeh.models import ColumnDataSource source = ColumnDataSource(x) bar = Bar(x, label='year', values='sales', agg='sum', stack='category', title="Expected Sales by year", tools = 'hover') hover = bar.select(dict(type=HoverTool)) hover.tooltips = [('Year', '@x'),('Sales', '@y')] show(bar) 

The result is the following diagram:

Bokeh tooltip does not display data

Addendum:

class ColumnDataSource (* args, ** kw)

probably the most important part of the solution (you can read about it here ).

+1
source

Source: https://habr.com/ru/post/1233269/


All Articles