使用plotly FigureWidget on_click功能绘制新图形

2024-09-28 03:23:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图使它在点击图形上的一个条时,一个新的图形用不同的数据绘制。当前,单击功能正常工作,但未绘制新图形:

# Standard plotly imports
import plotly as py
import plotly.graph_objs as go

#dataset1
x = ['a', 'b', 'c', 'd', 'e']
y = [10, 20, 30, 5, 25]

#dataset2
a = ['f', 'g', 'h', 'i', 'j']
b = [40, 80, 100, 10, 15]

#create first figure
f = go.FigureWidget([go.Bar(x = x, y = y)])
bar = f.data[0]

#click function to create new figure
def new_figure(trace, points, selector):
    for i in points.point_inds:
        print("CLICK")
        new = go.FigureWidget([go.Bar(x = a, y = b)])
        bar2 = new.data[0]
        new

bar.on_click(new_figure)

f

Here's the graph

有没有关于第二个数字没有被描绘出来我做错了什么的想法?提前谢谢


Tags: import图形gonewdataascreate绘制

热门问题