☰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

Legend with two glyph in the same line with different colors

Community Support
katamarandameko
katamarandameko

Dear all,

I write bokeh for around a month now. I would like to know if it is possible to add a Legend with two glyph with different colors.

So you have a very helpful example here:

If I wanted to add a Legend for the two boxes I would normally do:

# boxes
box1 = p.vbar(latest_queries, 0.7, q2.score, q3.score, fill_color="#E08E79", line_color="black")
box2 = p.vbar(latest_queries, 0.7, q1.score, q2.score, fill_color="#3B8686", line_color="black")

And then later on:

legend = Legend(items=[('Latest results', [box1,box2]), location="bottom_left")

However this will result in a Legend with one box with only the first color.
Is there a way to create a custom Legend with two glyph, but in the same line and with the same text?

⌁   Link to post
carolyn
carolyn

Hi katamarandameko,

One way to do it is to add the legend argument when you declare the glyphs. Like this:

p.vbar(cats, 0.7, q2.score, q3.score, fill_color="#E08E79", line_color="black", legend='thing 1')
p.vbar(cats, 0.7, q1.score, q2.score, fill_color="#3B8686", line_color="black", legend='thing 2')

You could also manually build the legend out of LegendItems you define, but it’d need one LegendItem per renderer:

box1 = p.vbar(cats, 0.7, q2.score, q3.score, fill_color="#E08E79", line_color="black")
box2 = p.vbar(cats, 0.7, q1.score, q2.score, fill_color="#3B8686", line_color="black")

legend = Legend(
    items=[
        LegendItem(label='thing 1', renderers=[box1]),
        LegendItem(label='thing 2', renderers=[box2])
    ]
)

I’m not sure about adding your ‘Latest Results’ title, so I’ll leave that part for others to answer. :slight_smile:

⌁   Link to post
katamarandameko
katamarandameko

I believe it does not work differently than the example that I have provided.

It is my fault that I haven’t included an image of how I would like the result to be:

example

There are two boxes with different color side by side and then one legend text.

⌁   Link to post

End of archived discussion · Replies are disabled