Bokeh 中的数据工具提示不显示数据,显示“???"反而
问题描述
来自维护者的注意事项:这个问题与几年前被删除的过时的 bokeh.charts
API 有关.有关现代散景中带有条形图的悬停工具的信息,请参阅此部分:
如您所见,数据被问号替换.我在 Ubuntu 15.04(64 位)上运行的 FF 41.0.1 和 Chromium 45.0.2454.101 上都得到了这个结果.
我阅读了散景教程http://docs.bokeh.org/en/latest/docs/user_guide/tools.html#hovertool
但它不指条形图.我还在 Stackoverflow 上找到了这个:
散景悬停工具提示不显示所有数据 - Ipython 笔记本.
这个问题可能是相关的,但坦率地说我不太明白答案.
解决方案我也遇到了同样的问题.我发现 this reference 很有用.Sales 的工具提示将使用通用的 @height
,例如:hover.tooltips = [('Sales', '@height')]
同样,将 @height
替换为 @y
可以得到每年的总销售额.我还没有弄清楚如何使用工具提示来访问堆叠的类别或如何使用链接中提到的 ColumnDataSource.
Note from maintainers: this question concerns the obsolete bokeh.charts
API that was removed several years ago. See this section for information about hover tools with Bar charts in modern Bokeh:
https://docs.bokeh.org/en/latest/docs/user_guide/categorical.html#hover-tools
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://docs.bokeh.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.
相关文章