0

I feel like I wrote too much code to put the labels above each bar. How can I optimize this code?

The dataset is ds_survey

ds_survey.plot(kind ='bar', 
          figsize=(10, 8),
          width = 0.35, 
         )

xlocs, xlabs = plt.xticks()
y = ds_survey['Interested']
for i, v in enumerate(y):
    plt.text(xlocs[i] - 0.35, v + 0.4, str(v))

y = ds_survey['Little interested']
for i, v in enumerate(y):
    plt.text(xlocs[i] - 0.1, v + 0.4, str(v))

y = ds_survey['Dont Want']
for i, v in enumerate(y):
    plt.text(xlocs[i]+0.2, v + 0.4, str(v))

plt.show()
frankzk
  • 556
  • 2
  • 6
  • 14

0 Answers0