-1

I'm looking to put the value of each bar (which is on the y-axis) inside of each bar as text. I've only found solutions online for matlab plots/heatmaps but can't find any for stacked bar charts. Any help would be much appreciated.

enter image description here

This is what my dataframe looks like: dataframe

This is what I want the plot to look like:

ideal plot

Valkiyare
  • 19
  • 1
  • 1
  • 6
  • https://stackoverflow.com/a/49952248/6361531 – Scott Boston Aug 21 '19 at 12:53
  • @Scott Boston thank you for the answer - how would I adjust the code for both variables being categorical (i.e. race and threat level?) – Valkiyare Aug 21 '19 at 13:01
  • you'll need to add some sample data and expected graph output to this question to get a better example of how to adjust this code. Please edit the question and add sample data along with a image of how you would like the graph to look. https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples?answertab=oldest#tab-top – Scott Boston Aug 21 '19 at 13:04
  • @Scott Boston thank you, i'm a newbie to this site, I've added pictures of my dataframe and ideal plot :) – Valkiyare Aug 21 '19 at 13:22
  • This better, but to help others help you, I would advise you to look at that how to make good reproducible pandas examples. Adding images of the dataframe in the question doesn't help those who are trying to help you. Please take time to study (https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples?answertab=oldest#tab-top) and the code to generate a dataframe. This SO overflow community with doing less work with their volunteered time. Thank you. – Scott Boston Aug 21 '19 at 13:28

1 Answers1

0

If you want to put the value on top the bar then you should use this approach.(example)

       fig, ax = plt.subplots()
       rects1 = ax.bar(ind, men_means, width, color='r', yerr=men_std)
       for rect in rects:
          height = rect.get_height()
          ax.text(rect.get_x() + rect.get_width()/2., 1.05*height,'%d' % int(height),
          ha='center', va='bottom')
Aniket Dixit
  • 152
  • 1
  • 5