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

Time:01-12

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

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

CodePudding user response:

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

  • Related