Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Allow BoxAnnotations in Legends #12117

Open
mosc9575 opened this issue May 3, 2022 · 1 comment
Open

[FEATURE] Allow BoxAnnotations in Legends #12117

mosc9575 opened this issue May 3, 2022 · 1 comment

Comments

@mosc9575
Copy link
Contributor

mosc9575 commented May 3, 2022

Problem description

Sometimes I use BoxAnnotations to add additional information to a plot and I would like to have the opportunity to toggle visibility using a legend in the same way it is possible for Glyphs.

This is a slightly adapted version of the box_annotation example.

from bokeh.models import BoxAnnotation, Legend, LegendItem
from bokeh.plotting import figure, show
from bokeh.sampledata.glucose import data

data = data.loc['2010-10-04':'2010-10-04']

p = figure(title="Glocose Readings, Oct 4th\n(Red = Outside Range)",
           x_axis_type="datetime", tools="pan,wheel_zoom,box_zoom,reset,save")
p.background_fill_color = "#efefef"
p.xgrid.grid_line_color=None
p.xaxis.axis_label = 'Time'
p.yaxis.axis_label = 'Value'

p.line(data.index, data.glucose, line_color='grey')
p.scatter(data.index, data.glucose, color='grey', size=1)

boxes = []
boxes.append(BoxAnnotation(top=80, fill_alpha=0.1, fill_color='red', line_color='red'))
boxes.append(BoxAnnotation(bottom=180, fill_alpha=0.1, fill_color='red', line_color='red'))
p.renderers.extend(boxes)
# p.add_layout(Legend(items=[LegendItem(label='Background', renderers=boxes)]))
show(p)

If I uncommet the line with the Legend I get the error message:

ValueError: failed to validate LegendItem(id='2918', ...).renderers: expected an element of List(Instance(GlyphRenderer)), got seq with invalid items [BoxAnnotation(id='2916', ...), BoxAnnotation(id='2917', ...)]

Feature description

This is possibly a dupliacte, I found this comment in #9955

Allow annotations to be added to legends (this has come up several times recently)

Additional information

I am using Bokeh 2.4.2 and don't know if this already is changed on the development branch.

@mosc9575 mosc9575 added the TRIAGE label May 3, 2022
@mattpap
Copy link
Contributor

mattpap commented May 3, 2022

Hopefully PR #12083, or a follow-up to it, will allow this.

@mattpap mattpap added this to the 3.0 milestone May 3, 2022
@bryevdv bryevdv modified the milestones: 3.0, 3.1 Jun 22, 2022
@mattpap mattpap modified the milestones: 3.1, 3.2 Feb 10, 2023
@mattpap mattpap modified the milestones: 3.2, 3.3 Jun 7, 2023
@mattpap mattpap modified the milestones: 3.3, 3.x Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants