我正在使用on_drag
的{{1}}个功能。而且我注意到它有点滞后..
我不确定这是不是
所以我的代码是以下
bqplot
它只是两点连接 你可以拖动蓝色的 我注意到的是,这条线路略微落后于蓝点。
答案 0 :(得分:0)
您无法直接在一条线上拖动一个点。您的方法只是我知道的方法,因此该行将始终遵循散点。我无法让你的代码明显加快。
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)
# scatt2.update_on_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):
# with lin.hold_sync():
lin.x=[lin.x[0], value['point']['x']]
lin.y=[lin.y[0], value['point']['y']]
# scatt2.on_drag_start(call_back2)
scatt2.on_drag(call_back2 )
# scatt2.on_drag_end(call_back2)
实际上可以做到。使用jslink。特征必须是相同的类型和长度/大小。在这种情况下,' x'并且' y'线条和散点标记的特征是长度为2的数组。
from bqplot import pyplot as plt
from ipywidgets import jslink
fig = plt.figure()
# Strange bug when 1st point is 0,0. Red point flickers.
lin=plt.plot([0.0001,1],
[0.0001,0])
scatt2=plt.scatter(lin.x, lin.y, enable_move = True, colors = ['Red','blue'])
scatt2.update_on_move = True
# Cover up 1st point so it can't be moved.
# Just remove this line if you want both points to be moveable
scatt3=plt.scatter([lin.x[0]], [lin.y[0]], colors = ['Red'])
plt.xlim(-3,3)
plt.ylim(-3,3)
fig.layout.height = '500px'
fig.layout.width = '500px'
plt.show()
jslink((scatt2, 'x'), (lin, 'x'))
jslink((scatt2, 'y'), (lin, 'y'))
Jslink并不需要Python内核来实现交互性。 您可以通过以下方式创建html文件(和js目录):
import ipyvolume.embed
ipyvolume.embed.embed_html("bqplot.html", fig, offline=True, devmode=False)