Python绘制boxplot

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

ACC = {
   'Vgg16': [66.3, 74.46, 99.64, 73.79, 92.51, 76.09, 89.67, 78.99, 66.30, 76.27, 93.84, 94.20, 97.46, 97.10],
 'Alexnet': [78.62 ,82.61, 99.82, 81.04, 97.95, 86.23, 91.49, 85.87, 96.20, 79.35, 97.46, 93.84, 98.91, 99.64],
  'Resnet18': [66.49, 71.01 ,99.09, 74.64, 93.00, 72.10, 90.94, 78.99 ,90.58, 73.19, 92.93, 90.94, 96.01 ,98.19],
"Googlenet": [66.28, 70.65, 98.37, 68.72, 89.13, 72.64, 89.31, 70.11, 87.86, 69.38, 84.06, 84.42, 98.34, 98.19],
"EfficientNet_b0": [61.78, 67.03, 97.28 ,64.86, 86.84 ,67.21, 82.79 ,70.47, 90.58, 64.13, 82.61, 80.43 ,88.77 ,95.29]
}

Pre = {
   'Vgg16': [66, 77 ,99 ,72 ,91, 86, 85, 79, 91, 70, 97 ,94, 98, 960],
 'Alexnet': [77 ,83 ,99, 79, 97, 88, 86, 87 ,95, 79, 97, 95, 99 ,100],
  'Resnet18': [71, 71, 100 ,75, 92, 74 ,88, 78, 91, 73, 90,88 ,97 ,97],
"Googlenet": [63 ,70 ,98, 67, 86, 74, 84, 69, 86, 67, 83, 86, 94 ,97],
"EfficientNet_b0": [62 ,71, 96, 66 ,84, 74, 82, 73, 90, 65, 77, 77, 90, 97]
}

Rec = {
   'Vgg16': [48, 67, 99, 75 ,95, 59 ,97 ,79, 89 ,86,92 ,95, 97 ,99],
 'Alexnet': [77 ,80, 100, 83, 99, 83, 99, 85, 98, 82, 97 ,92, 98 ,99],
  'Resnet18': [58, 74, 98, 75, 95 ,66, 97, 82, 91, 74, 96, 96, 95, 99],
"Googlenet": [64, 69, 99, 71, 94 ,67, 98, 69, 89, 76 ,85, 85, 93, 99],
"EfficientNet_b0": [57, 62 ,98, 64, 90, 60 ,85 ,70 ,91 ,67, 89, 85, 87, 95]
}

Spe = {
   'Vgg16': [87.0 ,81.4 ,100,72.3, 90.0, 91.8, 81.6, 78.5 ,90.7, 67.1, 96.6 ,93.4, 97.7, 94.4],
 'Alexnet': [80.4 ,85.6, 99.6 ,78.9 ,97.2,89.1 ,84.3 ,86.6, 94.0, 75.9 ,97.6, 95.8, 99.3 ,100],
  'Resnet18': [75.8 ,67.9 ,100 ,73.8 ,90.7,77.8, 83.9 ,76.8 ,90.5 ,72.0,  90.1 ,85.2, 96.9 ,97.0],
"Googlenet": [61.0 ,72.3, 98.2, 66.9, 84.7 ,78.2, 80.3 ,71.2, 86.4, 63.9, 83.3 ,85.3 ,94.5 ,97.4],
"EfficientNet_b0": [66.4 ,72.6 ,96.4, 65.3 ,83.8, 75.2,80.1, 71.5, 90.2, 60.9, 76.7 ,76.1 ,90.5 ,96.1]
}
AUC = {
   'Vgg16': [66.30, 74.46, 99.64 ,73.79 ,92.51 ,76.09, 89.67, 78.99, 66.30, 76.27 ,93.84, 94.20, 97.46 ,97.10],
 'Alexnet': [78.62 ,82.61, 99.82, 81.04, 97.95, 86.23, 91.49, 85.87, 96.20 ,79.35, 97.46, 93.84 ,98.91, 99.64],
  'Resnet18': [66.49 ,71.01, 99.09, 74.64, 93.00, 72.10 ,90.94, 78.99, 90.58, 73.19, 92.93, 90.94, 96.01, 98.19],
"Googlenet": [66.28 ,70.65 ,98.37,68.72, 89.13, 72.64, 89.31, 70.11 ,87.86 ,69.38, 84.06, 84.42, 98.34, 98.19],
"EfficientNet_b0": [61.78, 67.03 ,97.28 ,64.86,86.84, 67.21 ,82.79 ,70.47, 90.58, 64.13 ,82.61 ,80.43, 88.77 ,95.29]
}
color = ['orangered','g','red','blue','k']

df1 = pd.DataFrame(ACC)
plt.figure(figsize=(18,8))
plt.subplot(231)
f1 = df1.boxplot(return_type='dict')
for box, c in zip(f1['boxes'], color):
    box.set(color=c)    # 箱体边框颜色
for box, c in zip(f1['medians'], color):
    box.set(color=c)    # 箱体边框颜色

plt.ylabel('Accuracy (%)',fontsize=16)
plt.tick_params(axis='both',which='major',labelsize=14)
plt.xticks(rotation=15,fontsize=16)
plt.ylim(40,100)
plt.grid()

df2 = pd.DataFrame(Pre)
plt.subplot(232)
f2 = df2.boxplot(return_type='dict')
for box, c in zip(f2['boxes'], color):
    box.set(color=c)    # 箱体边框颜色
for box, c in zip(f2['medians'], color):
    box.set(color=c)    # 箱体边框颜色
plt.ylabel('Precision (%)',fontsize=16)
plt.tick_params(axis='both',which='major',labelsize=14)
plt.xticks(rotation=15,fontsize=16)
plt.ylim(40,100)
plt.grid()


df3 = pd.DataFrame(Rec)
plt.subplot(233)
f3 = df3.boxplot(return_type='dict')
for box, c in zip(f3['boxes'], color):
    box.set(color=c)    # 箱体边框颜色
for box, c in zip(f3['medians'], color):
    box.set(color=c)    # 箱体边框颜色
plt.ylabel('Recall (%)',fontsize=16)
plt.tick_params(axis='both',which='major',labelsize=14)
plt.xticks(rotation=15,fontsize=16)
plt.ylim(40,100)
plt.grid()

df4 = pd.DataFrame(Spe)
plt.subplot(234)
f4 = df3.boxplot(return_type='dict')
for box, c in zip(f4['boxes'], color):
    box.set(color=c)    # 箱体边框颜色
for box, c in zip(f4['medians'], color):
    box.set(color=c)    # 箱体边框颜色
plt.ylabel('Specificity (%)',fontsize=16)
plt.tick_params(axis='both',which='major',labelsize=14)
plt.xticks(rotation=15,fontsize=16)
plt.ylim(40,100)
plt.grid()

df5= pd.DataFrame(AUC)
plt.subplot(235)
f5 = df3.boxplot(return_type='dict')
for box, c in zip(f5['boxes'], color):
    box.set(color=c)    # 箱体边框颜色
for box, c in zip(f5['medians'], color):
    box.set(color=c)
plt.ylabel('AUC (%)',fontsize=16)
plt.tick_params(axis='both',which='major',labelsize=14)  #设置刻度大小和位置
plt.xticks(rotation=15,fontsize=16)
plt.ylim(40,100)
plt.grid()
plt.show()

结果显示:

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值