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