☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Access to legend_label

Community Support
odadoun
odadoun

Hi,
in the goal of moving my legend outside to the plot area
I need to be able to retrieve all my line legend_label.

From this trivial example :

p = figure(plot_width=400, plot_height=400)
c = p.line(x=[1,2,3,4,5], y=[4,2,4,5,3],legend_label='toto')

how can I retrieve “toto” name legend_label ?
By advance thank you
cheers
Olivier

⌁   Link to post
carolyn
carolyn

Hi @odadoun,

In your case, p.legend.items[0].label is set to 'toto'. (A print statement will show this in the python console for verification.)

I’m interested to see your solution for moving your legend outside, too!

⌁   Link to post
odadoun
odadoun

thanks perfect !
I have this

r = [standardfig.line(x='date', y=i, source=ColumnDataSource(value),
      color=next(colors), legend_label=key, line_width=3,
      name=i,hover_line_color="red",hover_line_width=4)
      for key,value in dict_filter_data[i].items()]

Now with your solution I can do

legend = Legend(items=
[(list(standardfig.legend.items[p.index(i)].label.values())[0],[i])  
for i in r],location="center")

and use

standardfig.add_layout(legend,'right')

Note that I have a small probleme :slight_smile: I have now 2 legends one inside the plot and another one outside …

⌁   Link to post

End of archived discussion · Replies are disabled