Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #make the simple dataframe
- married = ['M', "NO DATA", 'S']
- percentage = [68.7564554, 9.35558, 21.8879646]
- df = pd.DataFrame(married, percentage)
- df.reset_index(level=0, inplace=True)
- df.columns = ['percentage', 'married']
- #make the bar plot
- sns.barplot(x = 'married', y = 'percentage', data = df)
- plt.title('title')
- plt.xlabel('married')
- plt.ylabel('Percentage')
- #place the labels
- ax = plt.gca()
- y_max = df['percentage'].value_counts().max()
- ax.set_ylim(1)
- for p in ax.patches:
- ax.text(p.get_x() + p.get_width()/2., p.get_height(), '%d' %
- int(p.get_height()),
- fontsize=12, color='red', ha='center', va='bottom')
Add Comment
Please, Sign In to add comment