☰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

Length of grid lines

Community Supportbokeh
RickD
RickD

I have been using p.outer_width in a recent program. Is there a length property for the actual grid lines, p.xgrid and p.ygrid? I would like to measure width and height of a grid square.

⌁   Link to post
Bryan
Bryan

No, there is just cross_bounds as I stated. Like I said, it’s a fairly obscure property (you are the first person to ask about it in years) so adding more docs or examples has never risen much on the priority list.

The ref docs that I linked do state the purpose of the property: “Bounds for the rendered grid lines”, as well as the expected type for the values: Tuple(Float, Float).

So, something like:

xgrid.cross_bounds = (2, 8) 

will draw the x-grid only between 2 and 8 (along the y-axis) instead of always spanning the entire currently visible plot area. There is no option like “width” or “height” because that’s not enough information to know where to draw (width or height relative to what?)

⌁   Link to post
RickD
RickD

thanks, good point, relative to what? Perhaps we can do some math based on x1, y1 and x2,y2, so if x1=2 and y1=1 then x2=3 and y2=2, a line drawn thru these coordinates would be the hypoteneuse of rise over run. I am trying to measure the length of the rise and run in pixels. Is there a length property of a line that can do this? So the rise and run will both be lines or maybe rays.

⌁   Link to post
Bryan
Bryan

Maybe I have misunderstood your question. I thought you wanted to control the length of grid lines. There is no way to measure the length of grid lines. By default they always span the entire viewport. You can get the pixel dimensions of the viewport via plot.inner_width and plot.inner_height but note that these values are not available until the plot actually renders, since the exact dimensions depend on e.g how much space the axis or titles or other things take up outside the viewport. You can always read them in a CustomJS callback, or a Python callback, if you are running a Bokeh server app.

⌁   Link to post
RickD
RickD

ok sorry my bad,

lets assume we have a line segment glyph with x1, y1 and x2,y2 as coordinates. First, can we calculate the length of this segment? Picture the resulting segment as a triangle with the hypoteneuse at a 45 degree angle (the actual line segment) and then a right angle for the remainder of the triangle. Secondly can we somehow measure the rise and run of this triangle?

if there is a length property or way to calculate length then the rise would = y2-y1 and the run would = x2-x1

⌁   Link to post
RickD
RickD

here is some sample code, when I move the points of the line segment I would like my other 2 lines to move too . When the orange lines change length so should the grid lines

from bokeh.plotting import figure, output_file, show
from bokeh.models import ColumnDataSource, PointDrawTool
import math

source = ColumnDataSource(
    data = {'x': [1,2], 'y': [2,3],'x1': [2,2],'y1': [2,3],'x2': [1,2],'y2': [2,2]}
)


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

#plot.line(x, y, color="#FB8072", line_width=2)
#plot.line(x = 'x2', y = 'y2', color="#FB8072", line_width=2, source=source)
plot.line(x = 'x', y = 'y2', color="#FB8072", line_width=2, source=source)

#plot.line(x1, y1, color="#FB8072", line_width=2)
#plot.line(x = 'x1', y = 'y1', color="#FB8072", line_width=2, source=source)
plot.line(x = 'x1', y = 'y', color="#FB8072", line_width=2, source=source)
       # add line segment to plot
r_c = plot.scatter(x = 'x', y = 'y', size = 10, fill_color = 'red', line_color = 'black', alpha = 0.7, source = source)
r_l = plot.line(x = 'x', y = 'y', line_color = 'blue', line_width = 3, line_alpha = 0.7, source = source)

#xx=x1-x    # error unsuported operand -
#xx=y-x   #y is not defined
#console.log(xx)

tool = PointDrawTool(renderers=[r_c], add = False)
plot.add_tools(tool)
plot.toolbar.active_tap = tool

show(plot)
⌁   Link to post

End of archived discussion · Replies are disabled