這個問題在這里已經有了答案:
唯一的區別是酒吧的高度不同。
uj5u.com熱心網友回復:
如果您使用 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()
此代碼將導致圖表鏈接
條形圖顏色示例
有很多不同的顏色可供選擇。這是 matplotlib 可用顏色的鏈接。
https://matplotlib.org/stable/gallery/color/named_colors.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/357848.html
標籤:Python matplotlib 直方图
