Note from maintainers: This question concerns the obsolete first generation Bokeh server. For details about modern Bokeh server applications, see:
https://docs.bokeh.org/en/latest/docs/user_guide/server.html
OBSOLETE:
I am currently working on this simple project using bokeh plotting through a server, attempting to move a circle in a circle. The two examples that I have been trying to learn from are https://github.com/bokeh/bokeh/blob/master/examples/plotting/server/animated.py and https://github.com/bokeh/bokeh/blob/master/examples/plotting/server/line_animate.py
As their documentation is still very limited, if anyone could help, that would be great.
import time
import numpy as np
from bokeh.plotting import cursession, figure, show, output_server
output_server("circle_server")
pl = figure(y_range=(-2,2), x_range=(-2,2))
x=1
y=0
pl.circle(x, y, size=25, alpha=0.6, name="moving_circle")
pl.annulus(x=0,y=0, inner_radius = 1, outer_radius = 1, line_alpha=0.6)
show(pl)
renderer = pl.select(dict(name="moving_circle"))
ds = renderer[0].data_source
while True:
for rad in np.linspace(0,2*np.pi,100):
#rad = deg*np.pi/180
ds.data["x"] = np.cos(rad)
ds.data["y"] = np.sin(rad)
cursession().store_objects(ds)
time.sleep(0.1)
Note from maintainers: This question concerns the obsolete first generation Bokeh server. For details about modern Bokeh server applications, see:
https://docs.bokeh.org/en/latest/docs/user_guide/server.html
OBSOLETE:
From the docs here:
http://docs.bokeh.org/en/latest/docs/reference/plotting.html#bokeh.plotting.Figure.circle
circle(plot, *args, **kwargs) - Parameters:
x (str or list[float]) – values or field names of center x coordinates
y (str or list[float]) – values or field names of center y coordinates
So, you need to pass your values in a list. To fix it you can just add brackets in [x], [y], [np.cos(rad)] and [np.sin(rad)].
Here's a tested working solution: