python - 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)))
当我执行代码时,我得到了overall_rating 的图。When chose option potential, I got this plot which has trace zero and one . 梅西、罗纳尔多和伊涅斯塔在综合评分和潜力方面均名列前茅。所以它为他们显示了两个条形图。那么我可以对只显示与选择的特征相关的跟踪做些什么。
我在 jupyter notebook 中离线使用 plotly。
解决方案
通过用 update_traces 替换 add_trace 并在 FigureWidget() 中添加 (data=[{'type':'bar'}] ,我解决了这个问题。
推荐阅读
- linux - ipset hash: net, iface 不起作用。将物理接口 ethx 添加到网桥时
- wordpress - 无法在 Wordpress Woocommerce 中使用 Fontawesome 作为无序列表项目
- python - 系列的真值不明确 - 基于另一列值创建新的数据框列
- c# - 如何在 ListItemTemplate 中使用 TextBox 为 ListBox 创建绑定
- html - HTML & CSS - 你如何创建一个下拉菜单?
- python-3.7 - 如何每行只添加一个值?
- ios - iOS 设备上未收到 CloudKit 通知
- python - 如何创建具有多个目录的 Python 包
- javascript - 网格项目在较小的屏幕尺寸上消失
- javascript - 用新数据重新加载视觉对象后,Javascript 不会加载