I would like to be able to select a single line from a Bokeh multi_line plot. I can only find a way to select all multi-lines at once. My example works by using p.line instead, but that's really slow if you have a lot of lines. Here's an example:
import pandas as pd
import numpy as np
from bokeh.palettes import Spectral11
from bokeh.plotting import figure, show, output_file
output_file('temp.html')
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'))
print(toy_df)
numlines=len(toy_df.columns)
mypalette=Spectral11[0:numlines]
p = figure(width=500, height=300, x_axis_type="datetime")
line1 = p.line(toy_df.index,toy_df["a"])
line2 = p.line(toy_df.index,toy_df["b"])
line3 = p.line(toy_df.index,toy_df["c"])
line3.visible=False
show(p)
The previous code perfectly creates three lines and makes the third one invisible. For efficiency reasons, I would like replace line1, line2, line3 with a multi-line:
p.multi_line(xs=[toy_df.index.values]*numlines,
ys=[toy_df[name].values for name in toy_df],
line_color=mypalette,
line_width=5)
However, I cannot find a way to select one of the individual lines and to make it invisible. I also tried it using custom javascript, but that didn't provide me a solution either.
答案 0 :(得分:1)
一种方法是将要隐藏的行的alpha设置为零:
line_color
或者,您可以为要隐藏的行设置None
值output.flat<float32>().device(ctx->eigen_device<GPUDevice>()) = input.flat<float32>() + ....
。
答案 1 :(得分:1)
有关交互式解决方案,请尝试:
p.legend.click_policy = 'hide'
,然后单击相应的图例条目。