函数
>matplotlib.pyplot.plot(*args, **kwargs)
举例
每隔1s观测一次物体的速度,共观测10次,得以下数据
物体A: (2,1,3,6,9,7,4,4,3,1)
物体B: (9,7,5,6,6,4,3,2,1,1)
做折线图
import matplotlib.pyplot as plt
import numpy as np
index=np.arange(1,11)#横坐标
a=[2,1,3,6,9,7,4,4,3,1]
b=[9,7,5,6,6,4,3,2,1,1]
plt.figure(figsize=(9, 6), dpi=80)
plt.plot(index,a,color='yellow',linestyle='--',marker='s',markerfacecolor='red',label='A')
plt.plot(index,b,color='yellow',linestyle='-.',marker='o',markerfacecolor='blue',label='B')
plt.xlabel('Time')#横坐标名字
plt.ylabel('Speed')#纵坐标名字
plt.title('line')
plt.legend(loc = "best")#图例
plt.savefig('line.pdf')
plt.show()
作图结果为
参数介绍
基本参数
(1)color: 折线的颜色
(2)linestyle: 线条的样式
(3)marker: 点的形状
(4)markerfacecolor: 点的颜色,不设定时默认与折线颜色相同
完整参数
marker的参数为