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?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With