Plotly 交互式条形图在显示新轨迹之前不会删除以前的轨迹
Plotly interactive bar chart doesn't remove the previous trace before displaying new trace
我正在尝试创建交互式 plotly 条形图。
select_feat = widgets.Dropdown(options=['overall_rating', 'potential'], description='Feature')
fig_1 = go.FigureWidget()
def response_1(feature):
x = player_info.groupby(['player_name'])[feature].mean().nlargest(5)
val = list(x.values)
lab = list(x.index.values)
fig_1.add_trace(go.Bar(x=lab, y=val))
fig_1.update_layout(title='Top five playes by average')
VBox((fig_1, interactive(response_1, feature=select_feat)))
当我执行代码时,I got this plot for overall_rating. When chose option potential, I got this plot which has trace zero and one。梅西、C罗、伊涅斯塔在overall_rating和潜力上都位居前列。所以它为他们显示了两个栏。
那么我能对只显示选定的与特征相关的轨迹做些什么呢?
我在 jupyter notebook 中离线使用 plotly。
通过将 add_trace 替换为 update_traces 并在 FigureWidget() 中添加 (data=[{'type':'bar'}],我解决了问题。
我正在尝试创建交互式 plotly 条形图。
select_feat = widgets.Dropdown(options=['overall_rating', 'potential'], description='Feature')
fig_1 = go.FigureWidget()
def response_1(feature):
x = player_info.groupby(['player_name'])[feature].mean().nlargest(5)
val = list(x.values)
lab = list(x.index.values)
fig_1.add_trace(go.Bar(x=lab, y=val))
fig_1.update_layout(title='Top five playes by average')
VBox((fig_1, interactive(response_1, feature=select_feat)))
当我执行代码时,I got this plot for overall_rating. When chose option potential, I got this plot which has trace zero and one。梅西、C罗、伊涅斯塔在overall_rating和潜力上都位居前列。所以它为他们显示了两个栏。 那么我能对只显示选定的与特征相关的轨迹做些什么呢?
我在 jupyter notebook 中离线使用 plotly。
通过将 add_trace 替换为 update_traces 并在 FigureWidget() 中添加 (data=[{'type':'bar'}],我解决了问题。