When we use the bar chart in matplotlib python library, the default bar color is uniform. We can change it by simply using the set_color() property. For example, follow this code snippet-

import matplotlib.pyplot as plt

plt.figure()

barlist=plt.bar([1,2,3,4], [1,2,3,4])
barlist[0].set_color('r')
barlist[1].set_color('y')
plt.savefig('demo.png')

Here, barlist[0] means the first element of the list. I hope you already understand that the [0] and [1] indicate the index. So, the output would be –

5 1 vote
Article Rating
0
Would love your thoughts, please comment.x
()
x