在 plotly.express 的图表上列出俱乐部名称

问题描述 投票:0回答:0

我正在尝试对英超俱乐部进行互动总结。我看失球和接球得分。我想添加一个下拉列表,以便用户可以选择他感兴趣的俱乐部。我找到了这样的解决方案,但它为我创建了更多图表而不是替换原来的图表。有人可以帮我完成最后一步吗?

import pandas as pd
from ipywidgets import interact
import plotly.express as px

club_name = 4 * ['Arsenal'] + 4 * ['Liverpool']
type = 2 * ['scored', 'scored', 'lost', 'lost']
half = 2 * ['first', 'second', 'first', 'second']
how_much = 2 * [10, 15, 10, 5]

df = pd.DataFrame(
    data=zip(club_name, type, half, how_much),
    columns=['club_name', 'type', 'half', 'how_much']
)

def make_chart(team):
    fig = px.bar(
        df[df['club_name'] == team],
        x='type', 
        y='how_much', 
        color='half', 
        barmode='group'
    )
    fig.show()

team_dropdown = interact(make_chart, team=df.club_name.unique())
python plotly visualization
© www.soinside.com 2019 - 2024. All rights reserved.