Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

Plotly-python: Changing hovermode of stacked graph to not display cumulative values

I created a stacked bar chart on plotly. But when I hover over the bars, the default tooltip shows the cumulative values. How can I change the tooltip to display the values of that particular category.

In this image, I don't want the value beside A Kumble to be 100 but instead the length of that purple box.

Stacked bar chart

stats2 = ["Runs","Maidens","Wickets"]
stat_title = ["runs conceeded","maidens bowled","wickets taken"]
captains = summary3["Captain"].unique()
for stat in stats2:
pct_stat = "Percent " + stat
    fig3 = go.Figure(
    data=[
        go.Bar(
            name="Percent overs bowled by pacers at home",
            x=captains,
            y=summary3[(summary3["Pace/Spin"]=="Pace")&(summary3["Home/Away"]=="Home")]["Percent Overs"],
            offsetgroup=0
        ),
        go.Bar(
            name="Percent overs bowled by spinners at home",
            x=captains,
            y=summary3[(summary3["Pace/Spin"]=="Spin")&(summary3["Home/Away"]=="Home")]["Percent Overs"],
            offsetgroup=0,
            base=summary3[(summary3["Pace/Spin"]=="Pace")&(summary3["Home/Away"]=="Home")]["Percent Overs"]
        ),
        go.Bar(
            name="Percent overs     bowled by pacers away",
            x=captains,
            y=summary3[(summary3["Pace/Spin"]=="Pace")&(summary3["Home/Away"]=="Away")]["Percent Overs"],
            offsetgroup=0,
            base=summary3[summary3["Home/Away"]=="Home"].groupby(by=["Captain"])["Percent Overs"].sum()
        ),
        go.Bar(
            name="Percent overs bowled by spinners away",
            x=captains,
            y=summary3[(summary3["Pace/Spin"]=="Spin")&(summary3["Home/Away"]=="Away")]["Percent Overs"],
            offsetgroup=0,
            base=summary3[(summary3["Home/Away"]=="Home")|(summary3["Pace/Spin"]=="Pace")].groupby(by=["Captain"])["Percent Overs"].sum()
        ),
        go.Bar(
            name="Percent " + stat_title[stats2.index(stat)] + " by pacers at home",
            x=captains,
            y=summary3[(summary3["Pace/Spin"]=="Pace")&(summary3["Home/Away"]=="Home")][pct_stat],
            offsetgroup=1,
        ),
        go.Bar(
            name="Percent " + stat_title[stats2.index(stat)] + " by spinners at home",
            x=captains,
            y=summary3[(summary3["Pace/Spin"]=="Spin")&(summary3["Home/Away"]=="Home")][pct_stat],
            offsetgroup=1,
            base=summary3[(summary3["Pace/Spin"]=="Pace")&(summary3["Home/Away"]=="Home")][pct_stat],
        ),
        go.Bar(
            name="Percent " + stat_title[stats2.index(stat)] + " by pacers away",
            x=captains,
            y=summary3[(summary3["Pace/Spin"]=="Pace")&(summary3["Home/Away"]=="Away")][pct_stat],
            offsetgroup=1,
            base=summary3[summary3["Home/Away"]=="Home"].groupby(by=["Captain"])[pct_stat].sum()
        ),
        go.Bar(
            name="Percent " + stat_title[stats2.index(stat)] + " by spinners away",
            x=captains,
            y=summary3[(summary3["Pace/Spin"]=="Spin")&(summary3["Home/Away"]=="Away")][pct_stat],
            offsetgroup=1,
            base=summary3[(summary3["Home/Away"]=="Home")|(summary3["Pace/Spin"]=="Pace")].groupby(by=["Captain"])[pct_stat].sum()
        )
    ],
    layout=go.Layout(
        title="Percentage of overs and percentage of " + stat_title[stats2.index(stat)] + " comparison",
        xaxis_tickangle = -45,
        hovermode = "closest"
    )
)
fig3.show()

This is the total graph generated for one statistic

question from:https://stackoverflow.com/questions/65641010/plotly-python-changing-hovermode-of-stacked-graph-to-not-display-cumulative-val

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...