欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python——绘制成组柱状图

程序员文章站 2022-07-14 17:35:52
...

import matplotlib.pyplot as plt

list_00 = [0.16, 0.33, 0.20, 0.31]
list_01 = [0.05, 0.33, 0.39, 0.29]
list_02 = [0.07, 0.5, 0.26, 0.38]
list_03 = [0.04, 0.13, 0.19, 0.15]
name_list = ['A', 'B', 'C', 'D']
x = list(range(len(name_list)))
total_width, n = 0.8, 4
width = total_width / n
plt.bar(x, list_00, width=width, label='a', tick_label=name_list, fc='y')
for i in range(len(x)):
	x[i] = x[i] + width
plt.bar(x, list_01, width=width, label='b', fc='r')
for i in range(len(x)):
	x[i] = x[i] + width
plt.bar(x, list_02, width=width, label='c', fc='b')
for i in range(len(x)):
	x[i] = x[i] + width
plt.bar(x, list_03, width=width, label='d', fc='g')
plt.legend()
plt.show()

python——绘制成组柱状图