Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bokeh how to add legend to figure created by multi_line method?

Tags:

bokeh

I'm trying to add legend to a figure, which contains two lines created by multi_line method. Example:

p = figure(plot_width=300, plot_height=300)
p.multi_line(xs=[[4, 2, 5], [1, 3, 4]], ys=[[6, 5, 2], [6, 5, 7]], color=['blue','yellow'], legend="first")

In this case the legend is only for the first line. When the legend is defined as a list there is an error:

p.multi_line(xs=[[4, 2, 5], [1, 3, 4]], ys=[[6, 5, 2], [6, 5, 7]], color=['blue','yellow'], legend=["first","second"])

Is it possible to add legend to many lines?

like image 898
user187205 Avatar asked Jul 15 '15 00:07

user187205


1 Answers

On more recent releases (since 0.12.15, I think) its possible to add legends to multi_line plots. You simple need to add a 'legend' entry to your data source. Here is an example taken from the Google Groups discussion forum:

data = {'xs': [np.arange(5) * 1, np.arange(5) * 2],
        'ys': [np.ones(5) * 3, np.ones(5) * 4],
        'labels': ['one', 'two']}

source = ColumnDataSource(data)

p = figure(width=600, height=300)
p.multi_line(xs='xs', ys='ys', legend='labels', source=source)
like image 100
masta-g3 Avatar answered Sep 27 '22 22:09

masta-g3