报这个错误的原因是plt.bar(x, y)参数的数据类型不对 其中的y需要是numpy创建的数组,而不能是普通的列表 例如:import numpy as np import matplotlib.pyplot as plt x = [1, 2, 3]y = [2, 3, 2] 就会报错 y = np.array([2, 3, 2]) 就是好的 plt.bar(x, y)plt.legend(loc=[1, 0])plt.show()