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

How can I draw bars close to each other in matplotlib's bar function?

I have this bar chart, obtained in Seaborn, using barplot:

Seaborn picture

I have the bar chart for the same dataset, obtained by Matplotlib’s bar:
Matplotlib picture

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

Is there a way, a switch, etc. to get the bars in Matplotlib’s picture closer, like they are in the Seaborn version?

>Solution :

Convert your x data to strings, since bar can handle categorical data. Some sample code:

plt.bar(['1', '2', '97', '99'], [1, 2, 3, 4])

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