Hide/display multiple glyphs with one action

H everyone

I am plotting a 24 column DataFrame, where one of the 24 columns is highlighted, while the remainder 23 are plotted with a smaller circle radius and a lighter alpha.

I am using this to plot each of the 23 non-highlighted samples

for loop_index in sample_list:
    p.circle(x='index', y=loop_index, source=source, size=5, color='gray', alpha=0.3)

I already have some code that toggle visibility of a single glyph with callbacks, but what would be the strategy to make all 23 non highlighted circles disappear and keep only the point set of interest? Would be in the callback code? Is there a way to create a collection of glyphs and hide/show it?

Any help appreciated.

Thanks
Paulo

Bump. Any ideas?

Thanks

Paulo

···

On Wednesday, 21 November 2018 15:01:26 UTC-7, Paulo Nuin wrote:

H everyone

I am plotting a 24 column DataFrame, where one of the 24 columns is highlighted, while the remainder 23 are plotted with a smaller circle radius and a lighter alpha.

I am using this to plot each of the 23 non-highlighted samples

for loop_index in sample_list:

p.circle(x='index', y=loop_index, source=source, size=5, color='gray', alpha=0.3)

I already have some code that toggle visibility of a single glyph with callbacks, but what would be the strategy to make all 23 non highlighted circles disappear and keep only the point set of interest? Would be in the callback code? Is there a way to create a collection of glyphs and hide/show it?

Any help appreciated.

Thanks

Paulo

I have a similar problem. I am trying to create a matlab-style plot with a line plus marker on top. Since there is no natural way to do this in bokeh, I create it using two glphys:

p.line(xdata, ydata)
p.circle(xdata, ydata)

However, now both glyphs appear in the legend separately and I need to select them separately for hiding/showing. Is there a way to change this behavior?

I try to answer both questions in one example. Though I think it comes a bit late for @Paulo_Nuin :confused:

from bokeh.plotting import figure
from bokeh.models import ColumnDataSource
from bokeh.io import curdoc

cds_line = ColumnDataSource(data=dict(x=[0,3], y=[0,3]))
# define a cds with alpha vector to toggle visibility of each circle individually
cds_markers = ColumnDataSource(data=dict(x=[.5,1.5,2.5], y=[.5,1.5,2.5], alpha=[1,0.3,0.3], size=[10,5,5]))

p = figure()
# use the same label to plot only one LegendItem for both
p.line(x='x', y='y', source=cds_line, legend_label="test")
p.circle(x='x', y='y', alpha="alpha", size="size", source=cds_markers, legend_label="test")

curdoc().add_root(p)

Defining an alpha and size vector of the length of the x and y vectors will help to exactly define which will be displayed. This can of course be changed in a function.

For the legend problem basically the same legend_label should be enough to solve this problem. See also legend.py — Bokeh 2.4.2 Documentation

1 Like

For the legend problem basically the same legend_label should be enough to solve this problem.

Works like a charm! Thank you so much, @Matthias! :tada: :+1:

1 Like