☰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

Long legends

Community Support
quite68
quite68

Our legend has so many items in it that we cannot display them all without making the figure bigger just to accomodate the legend. (The legend is displayed to the right of the figure)

Is there some way we can display all the legend items without making the figure taller?

e.g.

  • make the legend scrollable
  • give the legend multiple tabs
  • split the legend into pages and make the pages selectable.

Currently using Bokeh 3.2.0

Thanks

⌁   Link to post
Bryan
Bryan

Legends are not scrollable, since they are drawn directly onto the raster canvas of the plot using low-level drawing APIs. Eventually Legends may become separate DOM objects which may allow for scrolling, etc. In the mean time, your best bet is probably the nrows and ncols properties of legends to have the items arranged into grids, instead of just one single long list. There are some full examples here:

https://docs.bokeh.org/en/latest/docs/user_guide/styling/plots.html#two-dimensional-layout

⌁   Link to post
mateusz
mateusz

With the just merged support for DOM legends (Add support for canvas and DOM rendering to `Legend` by mattpap · Pull Request #14028 · bokeh/bokeh · GitHub; bokeh 3.7.0.dev3) , it’s now quite easy to add at least basic/primitive support for scrollable legends like this:

import numpy as np

from bokeh.palettes import Spectral11
from bokeh.plotting import figure, show

p = figure(width=400, height=400)

y = 1
ys = np.array([1, 2, 3])

for color in Spectral11:
    p.scatter(x=[0, 1, 2], y=ys + y, size=[10, 15, 20], marker="circle", color=color, fill_alpha=0.5, legend_label=f"{color} item")
    y += 1

p.legend.location = "top_left"
p.legend.stylesheets.append("""
:host {
    max-height: 150px;
    overflow: scroll;
}
""")

show(p)

⌁   Link to post

End of archived discussion · Replies are disabled