import matplotlib.pyplot as plt plt.rcParams["font.family"] = 'SimHei' # 将字体改为中文 plt.rcParams['axes.unicode_minus'] = False # 设置了中文字体默认后,坐标的"-"号无法显示,设置这个参数就可以避免 y1 = [5,9,1,20,15,31] y2 = [-5,-9,-1,-20,-5,-1] plt.bar(range(len(y1)),y1,width=0.8,facecolor = 'b',edgecolor = 'white',label='柱状图1') plt.bar(range(len(y2)),y2,width=0.8,facecolor = 'g',edgecolor = 'white',label='柱状图2') plt.legend() plt.title('柱状图示例') plt.show()