Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set width of bokeh plot x-axis directly

Tags:

python

bokeh

I would like to define the width of my bokeh plots excluding ylabels.

I am making a gridplot() and the subplots have different xranges, but it's important they are have the same scale.

I can define the width in proportion to their xrange, but that doesn't quite work, as the size of the y axis label, throws it off slightly.

I have a workaround, which is to estimate the size of the ylabel in pixels, then add that to the width, but it's far from an ideal solution.

enter image description here

As you can see the bottom panel is slightly stretched.

like image 684
distracted-biologist Avatar asked Feb 02 '26 02:02

distracted-biologist


1 Answers

There's no direct way to do that. You have direct control over:

  • The plot_width and plot_height. These are the (pixel) dimensions of the entire HTML canvas (which includes axes and titles, etc.)

and

  • The min_border (and specific min_border_left, etc) properties. The let you provide a mimimum pixel size for the areas around the central plot area (i.e. where axes and titles live).

So if you want to exert finer control over the central plot region, you can control these two things to do it. E.g. if you make two plots with plot_width of 600 and give both min_border_left of 80, then as long as the axes and labels, etc. of both plots fit inside the 80 pixels the cental plot areas will have the same width of 520px.

like image 69
bigreddot Avatar answered Feb 03 '26 15:02

bigreddot