Hello everyone.
I have coded the following image :
And now I would like to turn it into subplots. I’m just looking for to get the principle so I’m fine with any subplots with my plot in. I will adapt it then.
Here’s my code :
from plotly import graph_objects as go
data = {
"Objectif":[15, 23, 32],
"Repas 1": [4, 8, 18],
"Repas 2": [11, 18, 18],
"Repas 3":[20,32,22],
"labels": [
"Protéine",
"Glucide",
"Lipide",
]
}
print(pd.DataFrame(data))
data_plot=[
go.Bar(
name="Objectif",
x=data["Objectif"],
y=data["labels"],
offsetgroup=0,
orientation = "h",
text = data["Objectif"],
textposition='auto',
textfont_size=12
)
]
nb_meal = 3
for meal in range(1,nb_meal+1):
print(meal)
data_plot.append(
go.Bar(
name=f"Repas {meal}",
x=data[f"Repas {meal}"],
y=data["labels"],
offsetgroup=1,
orientation = "h",
text = data[f"Repas {meal}"],
textposition='auto',
textfont_size=12,
base=None if meal == 1 else [sum(x) for x in zip(*[data[f"Repas {i}"] for i in range(1,meal)])]
)
)
fig = go.Figure(
data_plot,
layout=go.Layout(
title="Issue Types - Original and Models",
yaxis_title="Number of Issues"
)
)
fig.show()
I’ve been searching for hours to turn this code into subplots, maybe the way I code it is not suitable to become subplots… But I really wanted multiples double bar. And the only way I’ve found is to use go.figure(data = data, …)
So I can change my code it’s fine as long as the plot does not change, any which works is good haha.
Thank you for your help.
Best regards.