0

I am new to bokeh and trying to plot a graph.I have three lists say,

from bokeh.plotting import figure, show
x=[1,2,3,4,5,6,7,8,9,10,11]
y=[1,2,1,1,1,1,3,4,5,5,5]
c=[50,40,30,20,10,60,50,40,30,20,10]

p = figure(x_axis_type="datetime", title="Range", plot_height=350, plot_width=800)
p.xgrid.grid_line_color=None
p.ygrid.grid_line_alpha=0.5
p.xaxis.axis_label = 'Time'
p.yaxis.axis_label = 'Value'

p.line(x,y)
show(p)

I want to have a sort of time series like step function graph, where the x-axis is a continuous series of time (the list x) and the y-axis is the event (the list y) i.e. y-axis should have markings only till 5 (like 1,2,3,4,5) and the plotted points when hovered over by mouse pointer should show the corresponding value stored in c.

so for example for when time is x=1, then y=1, and c=50.

so that I know by looking at the x-axis at what time where the person was (out of 5 places 1,2,3,4,5 on the y-axis) and by placing my mouse what was the value at that time (the list c).

0

1 Answer 1

1

If you want to show tooltips only at specific points I wold add circles and set them as the only hover renderers like this:

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

x=[1,2,3,4,5,6,7,8,9,10,11]
y=[1,2,1,1,1,1,3,4,5,5,5]
c=[50,40,30,20,10,60,50,40,30,20,10]
source = ColumnDataSource({'x': x, 'y': y, 'c': c})

p = figure(x_axis_type="datetime", title="Range", plot_height=350, plot_width=800, tooltips = [('time', '@x'), ('place', '@y'), ('value','@c')])
p.xgrid.grid_line_color=None
p.ygrid.grid_line_alpha=0.5
p.xaxis.axis_label = 'Time'
p.yaxis.axis_label = 'Value'

lines = p.line('x','y', source=source)
circles = p.circle('x','y', source=source)

p.select_one(HoverTool).renderers = [circles]

show(p)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.