当前位置: 首页 > news >正文

Python绘制论文中的图形

一、条形图

  1. 使用场景:对多个实验方法的性能进行比较。
  2. 代码:
#条形图
import matplotlib.pyplot as plt
import numpy as np#实验数据,每一行代表一个method,每一列代表一个性能指标
dataacc = [[0.9504, 0.9315, 0.9420, 0.9409],[0.9223, 0.9231, 0.9314, 0.9220],[0.8926, 0.9005, 0.9075, 0.9197]]#横坐标的标签
tick_label=["Accuracy", "Precision", "Recall", "F1-score"]
x = np.arange(4)
#设置字体
plt.rcParams['font.sans-serif'] = ['Times New Roman']
plt.rcParams['axes.unicode_minus']=False
#字体大小
fs = 17
#设置画布大小
fig = plt.figure(figsize=(6, 4))
#绘制图形
plt.bar(x-0.125, dataacc[0], width = 0.125, color='white', edgecolor='red', hatch='//',zorder = 0, label = "method1")
plt.bar(x, dataacc[1], width = 0.125, color='white', hatch='\\\\', edgecolor='green',zorder = 0, label = "method2")
plt.bar(x+0.125, dataacc[2], width = 0.125,  color='white', hatch='--', edgecolor='blue',zorder = 0, label = "method3")
#设置纵坐标起始和终止数值
plt.ylim((0.75, 1))
plt.tick_params(labelsize=fs-2)
plt.grid(True, linestyle='--', alpha=0.5)
#设置图例,loc设置位置,ncol设置列数
plt.legend(loc = 1 ,ncol=3,fontsize=fs-4)
plt.xticks(x,tick_label)plt.xlabel("matrics",fontsize=fs)
plt.ylabel("performance", fontsize=fs)
#保存图形为pdf
plt.savefig('../bar_pic.pdf', format='pdf', dpi=400, bbox_inches='tight')

在这里插入图片描述

二、折线图

  1. 使用场景:对比趋势
  2. 代码:
#折线图
import matplotlib.pyplot as pltdata = [[0.9840, 0.9741, 0.9845],[0.9631, 0.9386, 0.9428],[0.9387, 0.9051, 0.9142],[0.9030, 0.8835, 0.8744],[0.8950, 0.8424, 0.8696]] 
plt.rcParams['font.sans-serif'] = ['Times New Roman']
plt.rcParams['axes.unicode_minus']=Falsefig = plt.figure(figsize=(5, 4))
fs = 17
lw = 1.5ax1 = fig.add_subplot(111)
ax1.plot(["1.0", "2.0", "3.0", "4.0", "5.0"], [x[0] for x in data], c = "black", marker='+', linewidth=lw, label = "method1")
ax1.plot(["1.0", "2.0", "3.0", "4.0", "5.0"], [x[1] for x in data], c = "brown", marker='o', linewidth=lw, label = "method2")
ax1.plot(["1.0", "2.0", "3.0", "4.0", "5.0"], [x[2] for x in data], c = "darkviolet", marker='v', linewidth=lw, label = "method3")ax1.set_ylim([0.7, 1])
ax1.tick_params(labelsize=fs-2)
ax1.set_ylabel('Accuracy', fontsize=fs)
ax1.set_xlabel('Time', fontsize=fs)plt.grid(True, linestyle='--', alpha=0.5)
plt.legend(loc = 0 ,fontsize=fs-2)plt.savefig('../line_pic.pdf', format='pdf', dpi=1200, bbox_inches='tight')

在这里插入图片描述

三、箱线图

  1. 使用场景:显示数据分散情况的统计图。
  2. 代码:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
#箱线图x = [data1,data2,data3,data4]plt.boxplot(x,widths=0.6,flierprops={"marker": "*", "markerfacecolor": "red","markeredgecolor":"none","markersize":"5"},labels=['Training set URL','Training set embedding','Testing set URL','Testing set embedding'])
# 添加标题和标签
plt.grid(linestyle="--", alpha=0.3)
plt.savefig('../box_pic.pdf', format='pdf', dpi=1200, bbox_inches='tight')
http://www.lryc.cn/news/204557.html

相关文章:

  • flutter复制口令返回app监听粘贴板
  • 学习pytorch14 损失函数与反向传播
  • windows平台下Qt Creator的下载与安装流程
  • 在 Python 中使用 Pillow 进行图像处理【3/4】
  • 【Java】迭代器的next方法
  • java智慧工地云平台源码,以物联网、移动互联网技术为基础,结合大数据、云计算等,实现工程管理绿色化、数字化、精细化、智能化的效果
  • Unity 通过jar包形式接入讯飞星火SDK
  • python轻量规则引擎rule-engine入门与应用实践
  • 栓Q八股文: C++ 14/17 新特性
  • 虚拟世界游戏定制开发:创造独一无二的虚拟体验
  • Tomcat及jdk安装下载及环境配置(超超超详解)
  • 专业安卓实时投屏软件:极限投屏(QtScrcpy作者开发)使用说明
  • C++:二叉搜索树的原理和模拟实现
  • 学习视觉CV Transformer (2)--Transformer原理及代码分析
  • 【AI视野·今日CV 计算机视觉论文速览 第271期】Thu, 19 Oct 2023
  • GoLong的学习之路(四)语法之循环语句
  • 【Lua语法】字符串
  • 程序员节的由来
  • 订水商城H5实战教程-03用户协议
  • 淘宝app商品详情源数据API接口(解决滑块问题)可高并发采集
  • xcode15一直显示正在连接iOS17真机问题解决
  • stm32通过AT指令与esp8622通信
  • Flutter 类似onResume 监听,解决入场动画卡顿
  • 1024勋章
  • C++栈、队列、优先级队列模拟+仿函数
  • ES挂载不上怎么处理?
  • 问题与分类
  • 021-Qt 配置GitHub Copilot
  • 如何使用 PostgreSQL 进行数据迁移和整合?
  • Qt Signals Slots VS QEvents - Qt跨线程异步操作性能测试与选取建议