我制作了一个堆积的条形图,需要将每一列的总和以及每一列中的各个块(带有百分比)相加。
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.