#15391·bokeh

ScaleBar in a side panel is drawn outside the plot

Author: ghostiee-11Created Aug 30, 2026Updated Aug 30, 2026

Software versions

bash
Python version        :  3.13.15 | packaged by conda-forge | (main, Aug 10 2026, 13:01:04) [Clang 19.1.7 ]
IPython version       :  (not installed)
Tornado version       :  6.5.8
NumPy version         :  2.5.2
Bokeh version         :  3.10.0
BokehJS static path   :  .../site-packages/bokeh/server/static
node.js version       :  v24.7.0
npm version           :  11.5.1
jupyter_bokeh version :  (not installed)
Operating system      :  macOS-26.2-arm64-arm-64bit-Mach-O

Also reproduced with 3.9.0 from CDN, and on branch-4.0 at 4.0.0.dev3.

Browser name and version

Chrome 151.0.7922.174

Jupyter notebook / Jupyter Lab version

Not applicable. I reproduced this with output_file() / save() in a plain saved page, and separately by building the same plot from CDN in the browser. I did not try it in a notebook.

Expected behavior

A ScaleBar added to a plot's side panel should fit inside the plot, the way a ColorBar does. The side panel should reserve as much width as the scale bar actually needs.

Observed behavior

The side panel is narrower than the scale bar, so the scale bar is drawn past the right edge of the plot and over whatever sits next to it.

Measuring the DOM for the example below (the plot is 300px wide, so its right edge is at x=300):

element x width right
right CanvasPanel 280 20 300
ScaleBar 280 44 324

So the panel reserves 20px while the scale bar renders 44px, and 24px hangs outside the plot. A ColorBar in the same position measures panel width 66 and element width 66, so that one is sized correctly.

This looks separate from #15376: there the panel is sized correctly and the annotation overflows on the axis the panel deliberately clamps to the frame, whereas here the reserved width itself is too small.

Example code

python
from bokeh.io import output_file, save
from bokeh.layouts import gridplot
from bokeh.models import Metric, Range1d, ScaleBar
from bokeh.plotting import figure

output_file("scalebar.html")

p = figure(width=300, height=120, toolbar_location="above")
p.line([1, 2, 3], [1, 2, 3])
p.add_layout(
    ScaleBar(
        range=Range1d(0, 10),
        unit="m",
        dimensional=Metric(base_unit="m"),
        orientation="vertical",
    ),
    "right",
)

save(gridplot(children=[[p]]))

Stack traceback or browser console output

Nothing is logged, this fails silently. The saved page's console only contains Bokeh's own startup lines:

[bokeh 3.10.0] setting log level to: 'info'
[bokeh 3.10.0] document idle at 74 ms

Screenshots

Image