【python】画线----Matplotlib 模块学习系列(一)

你说的曾经没有我的故事 提交于 2020-01-25 01:35:04

使用到的方法

  1. plt.figure() //可以理解为声明窗口
  2. plt.plot() // 线的坐标值
  3. plt.show() // 显示
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-1,1,50) //取值范围以及点数
y = 2*x+1 //方程
plt.figure(num=4, figsize=(4,3)) // 窗口名称 和 大小
plt.plot(x,y, color='red', linewidth=4) // 画线
plt.show()

在这里插入图片描述

多条线

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-1,1,50)
y1 = x**2
y2 = 2*x+1
plt.figure(num=4, figsize=(4,3))
plt.plot(x,y1, color='red', linewidth=2)
plt.plot(x,y2, color='green', linewidth=2, linestyle='--')
plt.show()

在这里插入图片描述

多窗口

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-1,1,50)
y1 = x**2
y2 = 2*x+1

plt.figure(num=4, figsize=(4,3))
plt.plot(x,y1, color='red', linewidth=2)

plt.figure(num=1, figsize=(4,3))
plt.plot(x,y2, color='red')

plt.show()

在这里插入图片描述

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!