python matplotlib绘制多条折线图

python matplotlib绘制多条折线图

代码

import matplotlib.pyplot as plt

x = [6, 24, 48, 72]
y1 = [87, 174, 225, 254]
y2 = [24, 97, 202, 225]
y3 = [110, 138, 177, 205]
y4 = [95, 68, 83, 105]
y5 = [72, 74, 76, 67]
plt.title('扩散速度')  # 折线图标题
plt.rcParams['font.sans-serif'] = ['SimHei']  # 显示汉字
plt.xlabel('时间')  # x轴标题
plt.ylabel('差值')  # y轴标题
plt.plot(x, y1, marker='o', markersize=3)  # 绘制折线图,添加数据点,设置点的大小
plt.plot(x, y2, marker='o', markersize=3)
plt.plot(x, y3, marker='o', markersize=3)
plt.plot(x, y4, marker='o', markersize=3)
plt.plot(x, y5, marker='o', markersize=3)

for a, b in zip(x, y1):
    plt.text(a, b, b, ha='center', va='bottom', fontsize=10)  # 设置数据标签位置及大小
for a, b in zip(x, y2):
    plt.text(a, b, b, ha='center', va='bottom', fontsize=10)
for a, b in zip(x, y3):
    plt.text(a, b, b, ha='center', va='bottom', fontsize=10)
for a, b in zip(x, y4):
    plt.text(a, b, b, ha='center', va='bottom', fontsize=10)
for a, b in zip(x, y5):
    plt.text(a, b, b, ha='center', va='bottom', fontsize=10)

plt.legend(['方案一', '方案二', '方案三', '方案四', '方案五'])  # 设置折线名称

plt.show()  # 显示折线图

折线图

在这里插入图片描述

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值