I have a vbar graph in which I’m using conditional colors for each bar. I was hoping I could put a legend on the graph that gives a description of what each color means.
@MABeatty If you use a ColumnDataSource for your data and add a field that describes each observation then you can use legend_group in the vbar glyph method. Below I used your data and added the label field.
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource
ptest=figure()
source = ColumnDataSource(dict(
x = [1, 2, 3, 4, 5],
top = [40,50,60,30,40],
color = ['red', 'green', 'blue', 'green', 'red'],
label = ['Thunderstorms', 'Rain', 'Blue sky', 'Rain', 'Thunderstorms'],
))
ptest.vbar(
x = 'x', top = 'top',
color = 'color',
legend_group = 'label',
source = source
)
output_notebook()
show(ptest)
Have a look in the documentation for more details regarding legends.