0

My Code:

ax = df_quests_event_ticket.plot.barh(stacked=True, figsize=(12, 9))

# .patches is everything inside of the chart
for rect in ax.patches:
    # Bar Dimensions
    height = rect.get_height()
    width = rect.get_width()
    x = rect.get_x()
    y = rect.get_y()
    
    

    # Bar Labels
    label_text = f'{width:.1f}%'  # format decimal values
    
    # ax.text(x, y, text)
    label_x = x + width / 2
    label_y = y + height / 2
    
    # only plot labels greater than given width
    if width > 0:
        ax.text(label_x, label_y, label_text, ha='center', va='center', fontsize=12) 


#Legend
ax.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.) ##problemn with positioning

#Labels
ax.set_ylabel("Quests", fontsize=18)
ax.set_xlabel("Percent of Audience", fontsize=18)

#Invert Y Axis
ax.invert_yaxis()

#Title
ax.set_title("Quest Completion")

plt.show()

Output: enter image description here

Can't seem to find a way to add the total % to the end of each Stacked Bar

Any help is appreciated!

dm2
  • 4,053
  • 3
  • 17
  • 28
MHB
  • 1
  • 2
  • 1
    Does this answer your question? [How to annotate stacked bar chart with the sum of each bar (Matplotlib)?](https://stackoverflow.com/questions/56121254/how-to-annotate-stacked-bar-chart-with-the-sum-of-each-bar-matplotlib) – AlexK May 08 '21 at 23:11
  • Also: [Displaying totals above stacked bars in barchart: matplotlib.pyplot](https://stackoverflow.com/q/21688028/9987623) – AlexK May 08 '21 at 23:13

0 Answers0