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()
2
  • Maybe you want this Commented Apr 21, 2019 at 3:08
  • For this type of questions always share some sample dataframe for reproducibility. Commented Apr 21, 2019 at 5:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.