0
import pandas as pd
import numpy as np

df_survey=pd.read_csv('Topic_Survey_Assignment(1).csv',index_col=0)
df_survey=df_survey.sort_values('Very interested',ascending=False)
df_survey.columns = list(map(str, df_survey.columns))

df_survey1=df_survey.div(2233).round(2)
df_survey1

import matplotlib as mpl
import matplotlib.pyplot as plt 
import numpy as np

df_survey1.plot(kind='bar',figsize=(20,8),width=0.8,color=['#5cb85c','#5bc0de','#d9534f'],edgecolor='none')  
plt.xlabel('Data Science Areas') 
plt.ylabel('Percentage of Respondents\'interest') 
plt.title('Percentage of Respondents\' interest in Data Science Areas', size=16)
plt.legend(fontsize=14)

and I get this

enter image description here

I want to display the percentage values above each bar. Help! I am a newbie to Python, so have no idea.

1 Answers1

0

You could place text at the base of each bar using matplotlib's text functionality at https://matplotlib.org/api/text_api.html?highlight=text#module-matplotlib.text and just use some '{}'.format(percentage) to dynamically update the percentages from your code? You would have to explicitly define the x and y locations of each text with this method though, or develop some formula like x = i/number_of_bars.

Reedinationer
  • 5,661
  • 1
  • 12
  • 33