0

My bar plot is shown in the image below: https://i.stack.imgur.com/cmmDs.png

However, the space between two graphs are too wide. I want the space to be less. My code is here:

import matplotlib.pyplot as plt

fig = plt.figure(figsize = (4, 3))
x = ['Grayscale', 'Colored']
y = [accuracy_gray-0.5, accuracy_colored-0.5]
plt.bar(x, y, color ='red',
        width = 0.3, bottom = 0.5, align='center')

plt.text(-0.08, 0.8, round(y[0]+0.5, 2))
plt.text(0.92, 0.8, round(y[1]+0.5, 2))

How could I narrow the space between, given that we can only use plt.bar() method, not something else?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
B Z
  • 3
  • 2
  • this question already has answers https://stackoverflow.com/questions/11597785/setting-spacing-between-grouped-bar-plots-in-matplotlib – Nin17 Apr 16 '22 at 18:55
  • Hi, this answer is using another method for bar plot but my question is about plot.bar, so I think it is a bit different. – B Z Apr 16 '22 at 20:20
  • They aren't different, you can do exactly the same thing with plt.bar – Nin17 Apr 16 '22 at 20:22
  • Still a bit confused. Could you show how I should modify my code based on that answer? – B Z Apr 16 '22 at 23:02
  • You change the width and figsize parameters until you get something that looks like what you want. Try something like this: ```plt.bar(x, y, color ='red', width = 0.7, bottom = 0.5, align='center') ``` – Nin17 Apr 17 '22 at 05:54

0 Answers0