我有以下函数用于更新python plot.ly中的一个点:
def arbitrary_plot_fn():
# define data
...
# define figure widget
fig=...
# define update_point fn
def update_point(trace, points, selector):
c = list(scatter.marker.color)
s = list(scatter.marker.size)
xs = np.array(points.xs)
ys = np.array(points.ys)
for i in points.point_inds:
print(i,results[i,0])
c[i] = available_colors[2]
s[i] = 20
with fig.batch_update():
scatter.marker.color = c
scatter.marker.size = s
# works
scatter.on_click(update_point)
# would prefer the following (which doesn't work) ~:
scatter.on_click(update_point(fig=fig)) # obviously would add a kwarg to update_point()
fig.show()
return
由于update_point
隐式地需要fig
,因此必须为每个图形重新定义该函数,这会导致大量冗余代码
我可以在每次重新定义时使用lambda来缩短回收时间,每个fig
一个
有没有一种方法可以通过简单地将fig
作为参数传递给update_point
来实现这一切
目前没有回答
相关问题 更多 >
编程相关推荐