日常学习记录——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()  # 显示折线图

运行结果:
三线对比折线图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值