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.
One way is to set alpha to zero for the line you want to hide:
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,
line_alpha=[1,0,1]) # hides second line
Alternatively, you can make the line_color value be None for the line you want to hide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With