0

I'm trying to draw a figure like the one below.

enter image description here

here is the code

x = [0, 1, 2]
y = [88909, 27155, 12897]
plt.bar(x, y, tick_label = ['Pre-K, elementary, and middle', 
    'Secondary and high', 'Other, ungraded, and n/a or not reported'])

to put a label inside each bar, I could use plt.text. However, I need to calculate the coordinates for each.

Is there a way to have some kind of lib do it for me, and I just need to provide the strings?

JJJohn
  • 915
  • 8
  • 26

1 Answers1

1

Based on this answer:


fig, ax = plt.subplots()
bars = ax.bar(x, y,tick_label = ['Pre-K, elementary, and middle', 
    'Secondary and high', 'Other, ungraded, and n/a or not reported'], )

ax.bar_label(bars,padding=-15)

YScharf
  • 1,638
  • 15
  • 20