Span boundaries

Hi,
I can make a span like this forexample

from bokeh.models import Span
Span(location=42,dimension='height', line_color='red',line_dash='dashed', line_width=3)

which is great. But can i somehow limit the Span between e.g. 50 and 60 in the width direction instead of it going between -inf to inf.

Alternatively, how do i draw a line from (x1,y1) to (x2,y2) based on a single entry in a columndatasource?

If I’m understanding your question correctly, it sounds like maybe you’re talking about a Segment? That would give you a line segment from (x1, y1) to (x2, y2), but as far as pulling it out of your CDS, that’ll depend on how your CDS is structured. Here’s a trivial example based on a (kind of silly) CDS:

from bokeh.models import ColumnDataSource, Segment
from bokeh.plotting import figure, show

x = [42]
y0 = [50]
y1 = [60]
cds = ColumnDataSource(data=dict(x=x, y0=y0, y1=y1))
p = figure(x_range=(0, 100), y_range=(0, 100))
s = Segment(x0='x', y0='y0', x1='x', y1='y1', line_color="#f4a582", line_width=3)
p.add_glyph(cds, s)
show(p)

See also the Segment reference.

Hi Carolyn,
Thanks this is exactly what i needed :slight_smile:

1 Like