How to customize bar colors?

QuestionsQuestions8 SkillsProMatplotlib Bar ChartsNov, 15 2025
0123

You can customize the bar colors in a bar chart by passing a list of colors to the color parameter of the bar() function. Here's an example:

import matplotlib.pyplot as plt

fruits = ['Apples', 'Bananas', 'Cherries']
counts = [10, 15, 7]
bar_colors = ['red', 'yellow', 'pink']

fig, ax = plt.subplots()
ax.bar(fruits, counts, color=bar_colors)
ax.set_ylabel('Fruit Supply')
ax.set_xlabel('Fruit Names')
ax.set_title('Fruit Supply by Kind')
plt.show()

In this example, each bar will have a different color as specified in the bar_colors list.

0 Comments

no data
Be the first to share your comment!