I am trying to plot a stacked bar plot where I have my data plotted as shown in the figure below. The labels are the exact values for each container. I would like to put these in percentage values of the total value of each bar. So far, I failed to do so. Your help would be appreciated.
Here is the code for labels:
for i, rect in enumerate(ax.patches):
# Find where everything is located
height = rect.get_height()
width = rect.get_width()
x = rect.get_x()
y = rect.get_y()
label_text = f"{height:.02f}"
label_x = x + width / 2
label_y = y + height / 2
ax.text(
label_x,
label_y,
label_text,
ha="center",
va="center",
fontsize=4,
weight="bold",
)

