300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 如何使用python画折线图-Python 使用 matplotlib 画折线图教程

如何使用python画折线图-Python 使用 matplotlib 画折线图教程

时间:2021-07-09 02:51:10

相关推荐

如何使用python画折线图-Python 使用 matplotlib 画折线图教程

话不多说,直接上代码。最近修改一篇论文,实验部分的图全部重画了一下,也正好在此进行整理。使用 Python 的 matplotlib 库来画图还是比较方便的,今天整理一下用 matplotlib 画折线图的方法。

一、Python 使用 matplotlib 画折线图# coding:utf-8

"""

Author: roguesir

Date: /8/30

GitHub:

Blog: /roguesir

"""

import numpy as np

import matplotlib.pyplot as plt

x1=[20,33,51,79,101,121,132,145,162,182,203,219,232,243,256,270,287,310,325]

y1=[49,48,48,48,48,87,106,123,155,191,233,261,278,284,297,307,341,319,341]

x2=[31,52,73,92,101,112,126,140,153,175,186,196,215,230,240,270,288,300]

y2=[48,48,48,48,49,89,162,237,302,378,443,472,522,597,628,661,690,702]

x3=[30,50,70,90,105,114,128,137,147,159,170,180,190,200,210,230,243,259,284,297,311]

y3=[48,48,48,48,66,173,351,472,586,712,804,899,994,1094,1198,1360,1458,1578,1734,1797,1892]

x=np.arange(20,350)

l1=plt.plot(x1,y1,'r--',label='type1')

l2=plt.plot(x2,y2,'g--',label='type2')

l3=plt.plot(x3,y3,'b--',label='type3')

plt.plot(x1,y1,'ro-',x2,y2,'g+-',x3,y3,'b^-')

plt.title('The Lasers in Three Conditions')

plt.xlabel('row')

plt.ylabel('column')

plt.legend()

plt.show()

根据自己的需要进行修改即可。

二、效果图

————————————————

版权声明:本文为CSDN博主「roguesir」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

原文链接:/roguesir/article/details/77839721

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。