Renaming values on x-axis on a bar chart in matplotlib

I have the following code:

df['booking_complete'].value_counts().plot(kind='bar', title='Incomplete vs Complete bookings')

which is displaying a bar chart with 0 (for incomplete) and 1 (for complete bookings) on x-axis. I want to rename the 0 to Incomplete and 1 to complete on the Bar chart.

enter image description here

df['booking_complete'].value_counts().plot(kind='bar', title='Incomplete vs Complete bookings')

>Solution :

You can replace 0 and 1 before creating the graph:

dmap = {0: 'Incomplete', 1: 'Complete'}
(df['booking_complete'].value_counts().rename(dmap)
     .plot.bar(title='Incomplete vs Complete bookings', rot=0, color='red'))
plt.show()

Output

enter image description here

Leave a Reply