import numpy as np from matplotlib import pyplot as plt # 这两行代码解决 plt 中文显示的问题 plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = False plt.figure(figsize=(9, 6)) n = 5 X = ['[1,2,3]','[2,3,4]','[3,4,5]','[4,5,6]','[5,6,7]'] Y1 = [71,72,72.1,71.3,71.6] # Y2 = np.random.uniform(0.5, 1.0, n) plt.bar(X, Y1, width=0.25, facecolor='lightskyblue', edgecolor='white') # width:柱的宽度 # plt.bar(X + 0.35, Y2, width=0.35, facecolor='yellowgreen', edgecolor='white') # 水平柱状图plt.barh,属性中宽度width变成了高度height # 打两组数据时用+ # facecolor柱状图里填充的颜色 # edgecolor是边框的颜色 # 想把一组数据打到下边,在数据前使用负号 # plt.bar(X, -Y2, width=width, facecolor='#ff9999', edgecolor='white') # # 给图加text # for x, y in zip(X, Y1): # plt.text(x + 0.3, y + 0.05, '%.2f' % y, ha='center', va='bottom') # # for x, y in zip(X, Y2): # plt.text(x + 0.6, y + 0.05, '%.2f' % y, ha='center', va='bottom') plt.ylim(66, 73) # 设置横纵坐标字体大小 plt.xticks(fontsize=15) plt.yticks(fontsize=15) # 设置横纵轴的文字 plt.xlabel("卷积核尺寸",{'size':15}) plt.ylabel("准确率/%",{'size':15}) plt.show()