5折实验结果画箱线图

【Python】5折实验结果画箱线图

箱线图的基础知识我这就不过多介绍了,有很多文章介绍(偷懒啦)。

表格数据如下:


读取表格数据

import pandas as pd
data = pd.read_excel('draw_resulft.xlsx',sheet_name='no')
data.head(10)

注意:以下这一步必须做,不然报错都不知道哪错了,就像我sheet前面有空格。坑已经踩过了!

data.keys()  # #查看sheet的名字


设置图表背景颜色字体

sns.set_style('darkgrid', {
    
    'font.sans-serif':['SimHei', 'Arial']})

设置横坐标显示的角度45°

plt.xticks(rotation=45)

设置使用的样式,可以查看这篇博客

默认设置,显示图如下:

在这里插入图片描述

plt.style.use('classic')

修改后,显示如下:
在这里插入图片描述

完整代码

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

data = pd.read_excel('draw_resulft.xlsx', sheet_name='no')
sns.set_style('darkgrid', {
    
    'font.sans-serif': ['SimHei', 'Arial']})  # 设置图表背景颜色字体
plt.style.use('classic') # 设置使用的样式
sns.boxplot(y=' mAP', data=data, x='model')
plt.xticks(rotation=45)  # 设置横坐标显示的角度45°
plt.title('5-flod mAP')
plt.tight_layout()
# plt.savefig('5-flod mAP.pdf')  # 保存为pdf
plt.savefig('5-flod mAP.png', dpi=600)

猜你喜欢

转载自blog.csdn.net/wuli_xin/article/details/127700889