代码运行如下:
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(4)
yl = np.array([11,8,9,13])
y2 = np.array([9,6,4,11])
#柱形宽度
bar_width = 0.4
#绘制柱形图
plt.bar(x, yl, tick_label=['a', 'b', 'c', 'd'],width=bar_width,color='pink')
plt.bar(x+bar_width, y2, width=bar_width,color='purple')
plt.show()
运行结果如下: