ru/mse.py

51 lines
2.1 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import matplotlib.pyplot as plt
import numpy as np
MCS = [ 'MI-FGSM', 'PGD', 'Adv-\nAttribute', 'Adv-\nDiffusion','TCA$^2$']
gold_medal = [ 54.82, 49.72, 50.12, 59.28,63.03]
silver_medal = [ 31.06, 24.57, 18.63, 32.61,36.08]
x = np.arange(len(MCS))
print(x)
width = 0.35
gold_x = x
silver_x = x + width
plt.bar(gold_x,gold_medal,width=width,color="royalblue", label='Face++')
plt.bar(silver_x,silver_medal,width=width,color="tomato", label='Aliyun')
# plt.bar(silver_x,silver_medal,width=width,color="silver")
plt.xticks(x+width, labels=MCS)
for i in range(len(MCS)):
plt.text(gold_x[i],gold_medal[i], gold_medal[i],va="bottom",ha="center",fontsize=8)
plt.text(silver_x[i],silver_medal[i], silver_medal[i],va="bottom",ha="center",fontsize=8)
# plt.text(bronze_x[i],bronze_medal[i], gold_medal[i],va="bottom",ha="center",fontsize=8)
plt.legend(loc=2,frameon=False)
plt.ylabel('Mean Confidence Scores')
plt.show()
# import matplotlib.pyplot as plt
# import numpy as np
# # 这两行代码解决 plt 中文显示的问题
# # plt.rcParams['font.sans-serif'] = ['SimHei']
# # plt.rcParams['axes.unicode_minus'] = False
# # 输入统计数据
# waters = ['clean', 'MI-FGSM', 'PGD', 'Adv-\nAttribute', 'Adv-\nDiffusion','TCA^2']
# buy_number_male = [10.22, 57.82, 53.72, 50.12, 59.28,61.03]
# buy_number_female = [0.51, 31.06, 24.57, 18.63, 32.61,33.08]
# bar_width = 0.3 # 条形宽度
# index_male = np.arange(len(waters)) # 男生条形图的横坐标
# index_female = index_male + bar_width # 女生条形图的横坐标
# # 使用两次 bar 函数画出两组条形图
# plt.bar(index_male, height=buy_number_male, width=bar_width, color='b', label='Face++')
# plt.bar(index_female, height=buy_number_female, width=bar_width, color='g', label='Aliyun')
# plt.legend() # 显示图例
# plt.xticks(index_male + bar_width/2, waters) # 让横坐标轴刻度显示 waters 里的饮用水, index_male + bar_width/2 为横坐标轴刻度的位置
# plt.ylabel('MCS') # 纵坐标轴标题
# plt.title('on') # 图形标题
# plt.show()