☰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

Placement of label relative to figure

Community Support
huaracheguarache
huaracheguarache

I’m trying to create a figure where I have labels in the lower left and upper left corners with some informational text. Creating a label in the lower left corner is simple enough, but how do I create one in the upper left corner when the plot is set to be dynamically scaled based on the screen size of the device rendering it? I can’t specify a y-coordinate in screen coordinates because I don’t know how large the plot will be beforehand. I also don’t want to specify one in data coordinates because I want the label to stay in the upper left corner when zooming in or panning around.

Below is a minimal script with the two labels and some filler data:

from bokeh.plotting import figure, show
from bokeh.models import Label

fig = figure(title='Label position test')
fig.sizing_mode = 'stretch_both'

fig.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)

lower_left = Label(x=5, y=5, x_units='screen', y_units='screen', text='Lower left corner')
fig.add_layout(lower_left)

# How can I position this relative to the upper bound of the figure?
upper_left = Label(x=5, y=500, x_units='screen', y_units='screen', text='Upper left corner')
fig.add_layout(upper_left)

show(fig)
⌁   Link to post
Bryan
Bryan

You can specify a negative value, which is offset from the opposite side.

⌁   Link to post
Bryan
Bryan

I’m not sure if something changed at some point or if my memory is just bad on this point. Looking at the code, it does not behave that way after all. I don’t have any simple workarounds to suggest either, unfortunately. You would have to do something like set up a range callback and update the label y-position whenever the range changes.

Please feel free to open a GitHub Issue about supporting this use-case.

⌁   Link to post

End of archived discussion · Replies are disabled