栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

日常学习记录——matplotlib绘制折线对比图

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

日常学习记录——matplotlib绘制折线对比图

matplotlib绘制折线对比图

matplotlib三线对比:

import matplotlib.pyplot as plt

base = [1, 2, 3, 4]

x1 = [0.15, 0.08, 0.04, 0.04]
y1 = [0.91, 0.95, 0.97, 0.91]

x2 = [0.15, 0.08, 0.04, 0.09]
y2 = [0.91, 0.94, 0.97, 0.88]

x3 = [0.08, 0.08, 0.08, 0.08]
y3 = [0.95, 0.95, 0.95, 0.95]

plt.subplot(1, 2, 1) # 子绘图1
plt.rcParams['font.sans-serif'] = ['Times New Roman']  # 设置字体
plt.xlabel('Level')  # x轴标题
plt.ylabel('Mean Accuracy')  # y轴标题

plt.plot(base, y1, marker='o', markersize=3, linestyle='--')  # 绘制折线图,添加数据点,设置点的大小
plt.plot(base, y2, marker='*', markersize=3, linestyle='-.')
plt.plot(base, y3, marker='s', markersize=3, linestyle='-')
plt.legend(['Algorithm 1', 'Algorithm 2', 'Algorithm 3'])  # 设置折线名称

plt.subplot(1, 2, 2) # 子绘图2
plt.rcParams['font.sans-serif'] = ['Times New Roman']  # 设置字体
plt.xlabel('Level')  # x轴标题
plt.ylabel('Standard Deviation')  # y轴标题
plt.plot(base, x1, marker='o', markersize=3, linestyle='--')  # 绘制折线图,添加数据点,设置点的大小
plt.plot(base, x2, marker='*', markersize=3, linestyle='-.')
plt.plot(base, x3, marker='s', markersize=3, linestyle='-')
plt.legend(['Algorithm 1', 'Algorithm 2', 'Algorithm 3'])  # 设置折线名称

plt.suptitle("Performance Comparison")
plt.show()  # 显示折线图

运行结果:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/884182.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号