我有一些带有一些字形的图形,但只想要显示某些字形的工具提示.目前有没有办法在Bokeh中实现这一目标?
或者,有没有办法将两个数字叠加在一起?似乎这会让我完成我想做的事情.
我想给Bokeh一个大熊猫数据框,以绘制一条多行的折线图.
x轴应该是df.index,每个df.columns应该是一个单独的行.
这就是我想做的事情:
import pandas as pd
import numpy as np
from bokeh.plotting import figure, show
toy_df = pd.DataFrame(data=np.random.rand(5,3), columns = ('a', 'b' ,'c'), index = pd.DatetimeIndex(start='01-01-2015',periods=5, freq='d'))
p = figure(width=1200, height=900, x_axis_type="datetime")
p.multi_line(df)
show(p)
Run Code Online (Sandbox Code Playgroud)
但是,我收到错误:
RuntimeError: Missing required glyph parameters: ys
Run Code Online (Sandbox Code Playgroud)
相反,我设法做到了这一点:
import pandas as pd
import numpy as np
from bokeh.plotting import figure, show
toy_df = pd.DataFrame(data=np.random.rand(5,3), columns = ('a', 'b' ,'c'), index = pd.DatetimeIndex(start='01-01-2015',periods=5, freq='d'))
ts_list_of_list = []
for i in range(0,len(toy_df.columns)):
ts_list_of_list.append(toy_df.index)
vals_list_of_list = toy_df.values.T.tolist()
p …Run Code Online (Sandbox Code Playgroud) 如同这个问题:
我发现hovertool没有用于multi_line图,这有点像挫折.这在"警告"下提到:http://bokeh.pydata.org/en/0.11.0/docs/reference/models/tools.html#bokeh.models.tools.HoverTool
这有什么工作吗?另外,如果我要实现这个功能,那么什么是一个好的起点,是否有任何具体要注意的地方?此外,当前的散景路线图中是否有此功能?
在下面的代码中,我想知道在“????”的位置放什么 以便悬停工具将显示系列的名称(在本例中为“系列 1”或“系列 2”)
from bokeh.plotting import figure, output_notebook, show
from bokeh.models import HoverTool, ColumnDataSource
output_notebook()
hover = HoverTool()
hover.tooltips=[("series name","????")]
f = figure(tools=[hover])
f.line([1,2,3],[2,1,5],legend="series 1")
f.line([1,2,3],[1,7,2],legend="series 2")
show(f)
Run Code Online (Sandbox Code Playgroud)
我知道您可以执行以下操作来完成这项工作(请参阅在散景中,如何将工具提示添加到时间序列图表(悬停工具)?)。但是,我将这些图嵌入到一个 HTML 文件中,每个图都有许多数据点,文件中有许多图,所以我有兴趣最小化嵌入 HTML 文件中的数据源的大小。
from bokeh.plotting import figure, output_notebook, show
from bokeh.models import HoverTool, ColumnDataSource
output_notebook()
hover = HoverTool()
hover.tooltips=[("series name","@legend")]
f = figure(tools=[hover])
data1 = ColumnDataSource({"x":[1,2,3], "y":[2,1,5], "legend":["series 1"]*3})
data2 = ColumnDataSource({"x":[1,2,3], "y":[1,7,2], "legend":["series 2"]*3})
f.line("x","y",source=data1, legend="series 1")
f.line("x","y",source=data2, legend="series 2")
show(f)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Bokeh并混合代码片段.我从Pandas DataFrame创建了下面的图表,它使用我想要的所有工具元素正确显示图表.但是,工具提示部分显示数据.
这是图表:

这是我的代码:
from bokeh.plotting import figure, show
from bokeh.io import output_notebook
from bokeh.models import HoverTool
from collections import OrderedDict
x = yearly_DF.index
y0 = yearly_DF.weight.values
y1 = yearly_DF.muscle_weight.values
y2 = yearly_DF.bodyfat_p.values
#output_notebook()
p = figure(plot_width=1000, plot_height=600,
tools="pan,box_zoom,reset,resize,save,crosshair,hover",
title="Annual Weight Change",
x_axis_label='Year',
y_axis_label='Weight',
toolbar_location="left"
)
hover = p.select(dict(type=HoverTool))
hover.tooltips = OrderedDict([('Year', '@x'),('Total Weight', '@y0'), ('Muscle Mass', '$y1'), ('BodyFat','$y2')])
output_notebook()
p.line(x, y0, legend="Weight")
p.line(x, y1, legend="Muscle Mass", line_color="red")
show(p)
Run Code Online (Sandbox Code Playgroud)
我已经使用Firefox 39.0,Chrome 43.0.2357.130(64位)和Safari 8.0.7进行了测试.我已经清除了缓存,并且在所有浏览器中都出现了相同的错误.我也做了pip install bokeh --upgrade以确保我运行的是最新版本.