I have an interactive Bokeh plot that's able to hide certain circle plots when clicking on the Legend. Now when I disable a plot by clicking on it, the plotted circles disappear but the annotations remain. Could someone explain to me how I can toggle those on/off all together or does anyone have a quick fix?
Here's a picture when it's toggled off:
I plot the circles + legend with the following code:
q.circle('lng', 'lat', source = source2, name='vri', color='red', size=5, hover_line_color="black", legend_label = 'VRI') vri_labels = LabelSet(x='lng', y='lat', text='kruispuntn', x_offset=5, y_offset=5, source=source2, text_font_size = '10pt') q.legend.location = "bottom_left" q.legend.click_policy="hide" q.add_layout(vri_labels) show(q)
score:5
Accepted answer
You can link the visible
property via a CustomJS
callback:
from bokeh.io import show
from bokeh.models import ColumnDataSource, LabelSet, CustomJS
from bokeh.plotting import figure
p = figure()
cds = ColumnDataSource(data=dict(x=[0, 1], y=[0, 1], z=[1, 0]))
for var, params in [('y', {}),
('z', {'color': 'green'})]:
renderer = p.circle('x', var, source=cds, legend_label=var, size=20, **params)
label_set = LabelSet(x='x', y=var, text=var, source=cds, x_offset=5, y_offset=5)
p.add_layout(label_set)
renderer.js_on_change('visible', CustomJS(args=dict(ls=label_set),
code="ls.visible = cb_obj.visible;"))
p.legend.click_policy = 'hide'
show(p)
Credit To: stackoverflow.com
Related Query
- Hide annotation alongside legend in Bokeh
- Bokeh Interactive legend hide multiple glyphs
- How to dynamically hide glyphs and legend items with Bokeh
- Hide legend entries in a plotly figure
- Add custom legend to bokeh Bar
- Bokeh Legend Object - passing assigned color to legend
- Hide Legend and Scale information on surface plot using pandas, plotly
- Bokeh Pandas legend outside plot
- Verbatim labels in legend in bokeh plots
- Interaction between CheckboxButtonGroup and Legend in complex bokeh plot
- Bokeh - legend outside the plot
- Is there a way to use bokeh box annotation to highlight the same time frame each day?
- Modify the legend of pandas bar plot
- How to put legend outside the plot with pandas
- Change main plot legend label text
- Is it possible to add a string as a legend item in matplotlib
- How can I set the x-axis as datetimes on a bokeh plot?
- Pandas dataframe hide index functionality?
- How to rotate X-axis labels in bokeh figure?
- Hide axis label only, not entire axis, in Pandas plot
- Legend only shows one label when plotting with pandas
- Pandas bar plot with specific colors and legend location?
- How to remove or hide x-axis labels from a seaborn / matplotlib plot
- Discrete legend in seaborn heatmap plot
- Plotting multiple lines with Bokeh and pandas
- AttributeError: Unknown property legend in seaborn
- Set the legend location of a pandas plot
- Plot pandas dataframe with subplots (subplots=True): Place legend and use tight layout
- Custom legend in Pandas bar plot (matplotlib)
- Pandas groupby object in legend on plot
More Query from same tag
- Pandas dataframe columns extension using another dataframe column values
- Calculating win percentage for individual teams based on pandas df
- splitting pandas df column into multiple columns
- Changing element in a dataframe
- Get corresponding index of median
- Why is pandas apply lambda slower than loop here?
- Time Wheel in python3 pandas
- Transpose a dataframe based on column entries with sequences
- pandas to_datetime() then concat() on DateTime Index
- Add index to duplicated items in Pandas Series
- moving a row of a pandas dataframe but index unchanged
- Pandas wrapper for Bloomberg api?
- Output a single row in pandas to an array
- Panel OLS in statsmodels (because it's deprecated in Pandas?)
- Merging/Concat/Joining two dataframes