代码 import matplotlib.pyplot as plt import numpy as np# 数据 categories = ['denoise', 'double-digit', '100% 5R'] existence = [0.9778, 0.9768, 0.9767] non_existence = [0.9772, 0.9767, 0.9778]# 设置每组柱状图的宽度 bar_width = 0.25# 计算每组柱状图的位置 x = np.arange(len(categories))# 设置全局字体大小 plt.rcParams['font.size'] = 18# 绘制柱状图 plt.bar(x, existence, width=bar_width, label='Apply') plt.bar(x + bar_width, non_existence, width=bar_width, label="Not apply")# 添加标题、标签和图例 plt.title('Transformer') # plt.ylabel('Acc') plt.xticks(x + bar_width / 2, categories)plt.yticks([0.976, 0.977, 0.978], ["97.6%", "97.7%", "97.8%"]) # 设置Y轴刻度plt.legend() plt.ylim(0.974, 0.98) # 必须再 legend() 后面# 显示图表 plt.tight_layout() plt.grid() plt.show() 结果