I was playing around with on_drag
features of bqplot
. and I noticed that it is slightly lagging..
I am not sure if this is
- real issue
- I do something inappropriate
- meant to work like it is
so the code I have is the following
from bqplot import pyplot as plt
import numpy as np
fig=plt.figure()
lin=plt.plot([0,1],
[0,0])
scatt1=plt.scatter([0],[0],colors=['Red'])
scatt2=plt.scatter([1],[0],enable_move=True)
plt.xlim(-3,3)
plt.ylim(-3,3)
fig.layout.height = '500px'
fig.layout.width = '500px'
plt.show()
def call_back2(name, value):
#print(value,name)
if value['point']:
X=value['point']['x']
Y=value['point']['y']
lin.x=[scatt1.x[0],(X-scatt1.x)[0]]
lin.y=[scatt1.y[0],(Y-scatt1.y)[0]]
scatt2.on_drag_start(call_back2)
scatt2.on_drag(call_back2)
scatt2.on_drag_end(call_back2)
it is simply two points connected and you can drag the blue one around what I notice is that the line ever so slightly lags behind the blue dot.
You can't directly drag a point on a line. Your method is only way to do it that I know of and so the line will always follow the scatter point. I couldn't get your code to go noticeably faster.
Edit:
Actually it can be done. Use jslink. The traits must be the same type and length/size. In this case, the 'x' and 'y' traits for the line and scatter marks are arrays of length 2.
Jslink doesn't need the Python kernel for the interactivity to work. You you can create a html file (and js directory) by: