I would like to stick the latest caracter of a Label text to the bottom right part of my figure for a given text and a given font size. For instance in the following example where my text is ‘this is super fun’ with a font size of “20px” the position is width/2+25 (I found it with dichotomy) .
width,height=400,300
p = figure(plot_width=width, plot_height=height)
MyText='this is super fun'
my_font_size = "20px"
labels = Label(x=width/2+25, y=0,x_units='screen', y_units='screen', text=MyText,text_font_size=my_font_size)
p.add_layout(labels)
The Label model has text_align and text_baseline properties that you can use to control the horizontal and vertical alignment meanings of x and y coordinates, respectively.
The default for text_align is left and the default for text_baseline is bottom. If you set the text_align to right, it should eliminate much of the trial and error to relocate the label to where you want.
A wrinkle is that the figure area includes the toolbar, I believe, so if you simply set the x property to width in your example, the text will be clipped. So, you’ll need to factor in the width of the toolbar (which at least is independent of any text you’ll want to provide) or put the toolbar somewhere else.
I think its probably due to the fact that the min_border property of the figure is something nonzero, which will affect things too. You can set that to 0 or account for it in the x-coordinate of the Label constructor, probably needing to account for 2X (if it places equal borders on the left and right?).
In the end, depending on your ultimate use case and how involved the layout becomes, you might want to work in data units, but that really depends on the larger application.