import matplotlib.pyplot as plt
1.plt.plot() #绘图函数
参数:
color: 线条颜色(例如color='b'设置为蓝色, ‘g'、'r'、‘y'、'b'、'w'分别为绿红黄黑白)
label: 线条标签,若要显示需要加plt.legend()
linestyle: 线条风格(’-‘、’--‘、’:‘、'-.' 分别为实线、破折线、虚线、点划线)
linewidth: 线条宽度
marker: 标记字符样式(可设置为'.'、'o' 等)
makersize:标记点大小
例:
x1 = [1, 2] y1 = [2, 3] x2 = [2, 4] y2 = [1, 3] plt.plot(x1, y1, color='r', linestyle='-', label='line1', marker='o') plt.plot(x2, y2, color='b', linestyle='-.', label='line2',marker='.') plt.legend() plt.show()
2.plt.xlabel()、plt.ylabel()、plt.title() #x、y轴标签函数、绘图标签
参数:
rotation: 标签旋转角度(一般我只用这一个参数)
例:
x1 = [1, 2] y1 = [2, 3] plt.plot(x1, y1) plt.xlabel('input', rotation='20') plt.ylabel('output', rotation='90') plt.title('test', rotation='60') plt.legend() plt.show()
3.绘制动态图
例:
x = [] y = [] for i in range(1, 30): j = i + 1 x.append(i) y.append(j) plt.plot(x, y) plt.pause(0.001)