0

I have made a stacked bar graph and need to add to totals on each column, as well as the individual blocks in each column (with percentages).

df_data_2.round(2)
#df_data_2

#graph1 =df_data_2.T.plot.bar(stacked = True)


#ax=graph1
plt.xlabel("QTR")
plt.ylabel("Revenue")
plt.title("On Prem Tran Rev: Quarterly Performance $M (% of Total)")
#plt.legend()


#For percentages-

counter = df_data_2.unstack().unstack()


percentage_dist = 100 * counter.divide(counter.sum(axis = 1), axis = 0)
#percentage_dist.plot.bar(stacked=True)


ax = percentage_dist.plot.bar(stacked=True)
for p in ax.patches:
    width, height = p.get_width(), p.get_height()
    x, y = p.get_xy() 
    ax.text(x+width/2+.45, 
            y+height/2, 
            '{:.1f} %'.format(height), 
            horizontalalignment='center', 
            verticalalignment='center')```


So far I have a stacked graph with the percentages for each individual box.
petezurich
  • 9,280
  • 9
  • 43
  • 57
  • 1
    What have you tried to solve that requirement? Where are you stuck? – Nico Haase Jun 19 '19 at 15:06
  • Everything in my code is what I have tried. I am at a loss for how I would go about adding the totals for each column, as well as the subtotals. I would think this is easy but cannot find anything examples out there – James Parke Jun 19 '19 at 19:57

0 Answers0