Change the width or set the different widths of bar chart in Matplotlib

You can change the width of bars in the Matplotlib bar chart by setting the color option in bar().

from matplotlib import pyplot

x = ['Fri', 'Sat', 'Sun']
y = [26, 31, 19]

pyplot.bar(x, y, width=0.2)
pyplot.savefig('narrow.jpg')

The default value is 0.8. The following shows bars with default width.

from matplotlib import pyplot

x = ['Fri', 'Sat', 'Sun']
y = [26, 31, 19]

pyplot.bar(x, y)
pyplot.savefig('bar.jpg')

Set different widths

Like changing colors, you can set the different widths by bars.

from matplotlib import pyplot

x = ['Fri', 'Sat', 'Sun']
y = [26, 31, 19]

widths = [0.3, 0.5, 1]

pyplot.bar(x, y, width=widths)
pyplot.savefig('width.jpg')

Matplotlib Bar chart

Matplotlib Tutorial