-1

I'm trying to display the labels for each bar correctly. i.e. label under each bar. enter image description here

My code is as follows:

#set seaborn plotting aesthetics
sns.set(style='white')

#create grouped bar chart
sns.barplot(x='Claim_Type', y='Claim_Amount', data=DARD,
            palette=['purple', 'steelblue'])

#add overall title
plt.title('Claim Type vs Claim Amount', fontsize=16)

#add axis titles
plt.xlabel('Claim Type')
plt.ylabel('Claim Amount')

#rotate x-axis labels
plt.xticks(rotation=45)
Redox
  • 9,321
  • 5
  • 9
  • 26
Zelia
  • 1

1 Answers1

0

The x-axis labels (xticklabels) for your plot are very long. You have also used rotation. By default, Seaborn / matplotlib will align the center of the label to the middle of the plot. So, the labels are not appearing to align correctly (although the center is) to the bars. You can correct this by using horizontal alignment = right, which will align the right end of the text to the bars. Along with setting the labels right, it will also make it easier to read.

Update the plt xticks line as below...

plt.xticks(rotation=45, ha='right')

Plot

enter image description here

Redox
  • 9,321
  • 5
  • 9
  • 26