
Change the color or set the different colors of bar chart in Matplotlib
The colors of bar charts in Matplotlib can be set like this.
from matplotlib import pyplot
x = ['Fri', 'Sat', 'Sun']
y = [26, 31, 19]
pyplot.bar(x, y, color='red')
pyplot.savefig('bar_red.jpg')

To change the bar color, set the color
option in bar(). That value can take the webcolor with #
prefix.
from matplotlib import pyplot
x = ['Fri', 'Sat', 'Sun']
y = [26, 31, 19]
pyplot.bar(x, y, color='#2ca34c')
pyplot.savefig('green.jpg')

Set different colors by bars
from matplotlib import pyplot
x = ['Fri', 'Sat', 'Sun']
y = [26, 31, 19]
colors = ['pink', 'yellow', '#c23e27']
pyplot.bar(x, y, color=colors)
pyplot.savefig('array.jpg')

The color argument can be set to the list.
Comments
Powered by Markdown