Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading