import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
from collections import namedtuple
fig, ax = plt.subplots()
n_groups = 6 #列数
data=(6,8,10,12,14,16) #每一列对应的数据
index=('a','b','c','d','e','f') #横坐标
bar_width = 0.35 #每条柱状的宽度
rects1 = ax.bar(index, data, bar_width,label='a') #绘制柱状图
ax.legend() #绘制图例(即右上角的方框)
fig.tight_layout()
plt.show()
输出结果: