Bokeh中的数据工具提示不显示数据,显示'???'代替 [英] Data tooltips in Bokeh don't show data, showing '???' instead

查看:364
本文介绍了Bokeh中的数据工具提示不显示数据,显示'???'代替的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Bokeh创建堆积条形图。我想使用悬停功能,在栏的每个部分显示相关数据,但不是数据Bokeh显示'???'。



I在名为Sales的工作表中,将数据存储在名为示例工作表的Excel文件中。该表如下所示:

 年类别销售额
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

我尝试运行以下代码:

  import numpy as np 
从bokeh.charts导入scipy作为sp
import Bar,output_file,显示
from bokeh.models import HoverTool
将pandas导入为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)

运行后,我在Python控制台中收到以下消息(我不认为它与该主题有关,但我仍然这么说):

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

然后在浏览器中查看下面的图表:



正如您所看到的,数据被替换为问号。我在FF 14.0.1和Chromium 45.0.2454.101上得到了这个结果,运行在Ubuntu 15.04(64位)上。

我阅读了Bokeh教程 http://bokeh.pydata.org/en/latest/docs/user_guide/ tools.html#hovertool ,但它不涉及条形图。我也发现这在Stackoverflow上:
Bokeh hover tooltip不显示所有数据 - Ipython笔记本
这个问题可能是相关的,但坦率地说,我不太明白答案。

解决方案

同样的问题。我发现此参考资料很有用。 Sales的工具提示将使用通用的 @height ,例如:
hover.tooltips = [('Sales','@height' )]



同样,用 @替换 @height y 会给你每年的总销售额。我还没有想出如何使用工具提示访问堆叠的类别或如何使用链接中引用的ColumnDataSource。


I'm trying to create a stacked bar chart using Bokeh. I'd like to use the hover feature, displaying the relevant data in each part of the bar, but instead of the data Bokeh shows '???'.

I got the data in an excel file called "Example worksheet", in a sheet called "Sales". The sheet looks like this:

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 the run I get the following message in Python console (I don't think it's related to the topic, but I put it anyway):

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

And then on the browser I get the following chart:

As you can see, the data is replaced by question marks. I got this result on 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 doesn't refer to bar charts. I also found this on Stackoverflow: Bokeh hover tooltip not displaying all data - Ipython notebook. The question might be related, but frankly I didn't quite understand the answer.

解决方案

I was having the same problem. I found this reference useful. The tooltip for Sales would use the generic @height, e.g.: hover.tooltips = [('Sales', '@height')]

Similarly, replacing @height with @y would give you the total sales for each year. I haven't figured out how to use the tooltip to access the stacked categories or how to use the ColumnDataSource referred to in the link.

这篇关于Bokeh中的数据工具提示不显示数据,显示'???'代替的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆