matplotlib.pyplot.plot 绘制点线图

方法常用参数:plt.plot(x, y, 'xxx', label=, linewidth=)

参数1:位置参数,点的横坐标,可迭代对象

参数2:位置参数,点的纵坐标,可迭代对象

参数3:位置参数,点和线的样式,字符串
此参数分三部分,点线的颜色、点的形状、线的形状
点线的颜色:g | green;b | blue;c | cyan 蓝绿色;m - magenta 品红色 ...
点的形状:. | 点儿;v | 实心倒三角;o | 实心圆;* | 实心五角星;+ | 加号 ...
线的形状:- | 实线;-- | 虚线;-. 点划线

参数 4:label 关键字参数,设置图例,需要调用 plt 或子图的 legend 方法

参数 5:linewidth 关键字参数,设置线的粗细

举个例子

  1 import numpy as np
  2 import matplotlib.pyplot as plt
  3
  4 fig = plt.figure()
  5 ax1 = fig.add_subplot(1, 2, 1)
  6 ax2 = fig.add_subplot(1, 2, 2)
  7 x = np.random.rand(11).cumsum()
  8 y = np.random.rand(11).cumsum()
  9 ax1.plot(x, y, 'c*-', label='ax1', linewidth=2)
 10 ax2.plot(x, y, 'm.-.', label='ax2', linewidth=1)
 11
 12 ax1.legend()
 13 ax1.set_title('hahaha')
 14 ax2.legend()
 15 ax2.set_title('xixixi')
 16 ax2.set_xlabel('hengzhou')
 17 ax2.set_ylabel('zongzhou')
 18
 19 plt.show()
7212994-e0c6008cf858e950.png
plt.plot 运行代码截图

猜你喜欢

转载自blog.csdn.net/weixin_33994429/article/details/86839176