Hi everyone !
Within the framework of the realization of an interface, I would like to put in a plot a “BoxAnnotation” which represents my robot in a surface of 2meters by 2meters. I just did it, but now my robot will move, and i will receive new position (x/y). Then i have to clear last position and give a new one. And I managed to do that too, but I can’t find the function to remove the “BoxAnnotation”.
I try to use the function “rerderers”, but i think i didnt correctly use her.
this is my code : I clear all useless function, but i dont touch all import (some of them are useless)
from bokeh.plotting import figure, output_file
from bokeh.models import Panel, Tabs
import numpy as np
import math
from bokeh.io import curdoc
from bokeh.io import output_notebook, show
output_notebook()
from bokeh.layouts import column, row
from bokeh.models.widgets import TextInput, Button, Paragraph
from bokeh.models import LinearAxis, Range1d,CheckboxButtonGroup,PreText,Select,CustomJS, ColumnDataSource, Slider, Panel, Tabs
from random import *
from bokeh.driving import count
import numpy as np
import time
from bokeh.models.annotations import BoxAnnotation
UPDATE_INTERVAL = 250
def GetPosRobot(p, source):
global interface4_data
dxRobot = int(interface4_data['xRobot'])
dyRobot = int(interface4_data['yRobot'])
p.circle(dxRobot, dyRobot, color='pink')
xlrobot = dxRobot + 10.5
xrrobot = dxRobot - 10.5
ytrobot = dyRobot + 12
ybrobot = dyRobot - 12
robot = BoxAnnotation(top = ytrobot, bottom = ybrobot, left = xlrobot, right = xrrobot, fill_alpha=0.1, fill_color='blue')
p.add_layout(robot)
return None
def update():
global interface4_data, p
N = 1
interface4_data = dict(xRobot = np.random.random(size=N) * 200,yRobot = np.random.random(size=N) * 200)
GetPosRobot(p, interface4_data)
for i in range(N):
print(interface4_data['xRobot'])
print(interface4_data['yRobot'])
p = figure(x_range=(0, 200), y_range=(0, 200))
doc=curdoc() fois
doc.add_root(p)
doc.add_periodic_callback(update, UPDATE_INTERVAL)