Access to legend_label

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

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!

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 …

Does

legend_label

is compatible with

add_layout

???

If you call add_layout before adding any renderers like line, there should be only one legend in the end.

Thanks. To construct my legend I need to retrieve it from legend_label of my lines. Then I can not call add_layout before line …