plt.plot绘制折线图

效果图:

完整代码示例:


import matplotlib.pyplot as plt
import numpy as np

# 这部分取决于自己的数据
list1=[0.4065934065934066, 0.36460630875478545, 0.3096169059463802, 0.28972668064282797, 0.3479020575123368,
       0.35584023513718976, 0.3460475624131414, 0.3403828982709334, 0.3460027485801309, 0.3571833486791547,
       0.3680110364535581, 0.3673057675548254, 0.3676232785741803, 0.37135327777609917, 0.3701973302085565,
       0.3680581528521983]
list2=[0.2991104626721584, 0.33150461294161954, 0.9357647642360869, 0.8258249027636771, 0.850536386243011,
       0.8081764211714296, 0.7204214151119417, 0.681321203881519, 0.6681062200426938, 0.6847047751801689,
       0.6939711050774144, 0.699724546494557, 0.7051765658696858, 0.7135789597478035, 0.7077069296379535,
       0.7038199161220178]
list3=[0.4606835540768008, 0.4721902143012912, 0.48798459877999817, 0.6486909063331037, 0.6229303707650281,
       0.6149580654852328, 0.7094726200534931, 0.7780259597849083, 0.7831515313132199, 0.7661560284924841,
       0.7962847899937866, 0.7941235644922721, 0.8042427914771403, 0.8007337353825325, 0.7942991638911298,
       0.7905591192763348]
list4=[0.0, 0.17072182580970457, 0.3613014993482567, 0.4233086898223983, 0.38994018210090825, 0.4116025459881214,
       0.3861223715938927, 0.3804154605653132, 0.3758903536073492, 0.33521975658622144, 0.34118952223057397,
       0.3517292735843124, 0.34588537581030526, 0.3422946031803883, 0.3477574320714352, 0.3449299137408632]

# 绘制CV曲线
plt.xlabel('index', size=15, family='Times New Roman')  # x轴和y轴
plt.ylabel('value', size=15, family='Times New Roman')

plt.ylim((-0.2, 2.4))  # y轴的范围
plt.xticks(np.arange(0, len(list1), 2))  # y轴的坐标范围是(0到L_CV这个list的长度),间隔是2
plt.yticks(np.arange(-0.2, 2.4, 0.2))

plt.plot(list(range(0, len(list1))), list1, marker="^", linewidth=2, linestyle=":", color="#ff4683")
plt.plot(list(range(0, len(list2))), list2, marker="o", linewidth=2, linestyle="--", color="#4e9dec")
plt.plot(list(range(0, len(list3))), list3, marker="v", linewidth=2, linestyle="-.", color="orange")
plt.plot(list(range(0, len(list4))), list4, marker="s", linewidth=2, linestyle="-.", color="green")

# 设置图例并且设置图例的字体及大小
font = {'family': 'Times New Roman',#字体
        'weight': 'normal',
        'size': 12,# 字号
        }
#图例的具体内容
plt.legend(["${list1_{1}}$", "${list2_{1}}$", "${list3_{1}}$", "${list4_{1}}$"], # ${list2_{1}}$,下划线后面的内容会显示为下标
           loc="upper right", # 显示位置
           prop=font)
# 画网格(用虚线)
plt.grid(linestyle='--')
# 保存和查看
plt.savefig("绘制折线图.png" , dpi=300) #  dpi是存储图像的分辨率
plt.show()

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值