如果使用 matplotlib 模块,条形图有一个颜色参数。在此参数中,您可以更改颜色。这是我编辑的 matplotlib.org 中的一些代码示例,用于向您展示。
import matplotlib.pyplot as plt
labels = ['G1', 'G2', 'G3', 'G4', 'G5']
men_means = [20, 35, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]
men_std = [2, 3, 4, 1, 2]
women_std = [3, 5, 2, 3, 3]
width = 0.35 # the width of the bars: can also be len(x) sequence
fig, ax = plt.subplots()
ax.bar(labels, men_means, width, yerr=men_std, label='Men', color = 'blue')
ax.bar(labels, women_means, width, yerr=women_std, bottom=men_means,
label='Women', color = 'pink')
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.legend()
plt.show()
此代码将导致图表链接
Bar Chart Color Example
有很多不同的颜色可供选择。这是 matplotlib 可用颜色的链接。
https://matplotlib.org/stable/gallery/color/named_colors.html