Matplotlib PyLab模块

Matplotlib PyLab模块

Matplotlib PyLab模块

  PyLab 是一个方便的模块,可在单个名称空间中批量导入 matplotlib.pyplot(用于绘图)和 NumPy(用于数学和使用数组)。

Matplotlib PyLab模块
Matplotlib PyLab模块

  PyLab 是一个 Python 包,它通过从 Python Numpy 和 Matplotlib 模块中导入函数,为我们提供 Python 编程中的命名空间,它与 MATLAB 接口非常相似。本文晓得博客为你介绍Matplotlib PyLab模块。

  推荐:PyCharm IDE中的最佳插件

PyLab模块安装

  PyLab 模块与 Matplotlib 包的安装一起安装。尽管如此,如果我们想在 Python 程序中使用这个模块,我们应该确保 Matplotlib 模块存在于我们的系统中。如果系统中不存在 Matplotlib,那么可使用 pip 安装程序命令来安装 Matplotlib 模块以获取 PyLab 模块:

pip install matplotlib

  推荐:如何在Windows上安装PIP

PyLab模块基本绘图

  绘制曲线是使用 plot 命令完成的。它需要一对相同长度的数组(或序列) –

from numpy import *
from pylab import *

x = linspace(-3, 3, 30)
y = x**2
plot(x, y)
show()

  上面的代码行生成以下输出 –

Matplotlib PyLab模块基本绘图
Matplotlib PyLab模块

  要绘制符号而不是线条,请提供额外的字符串参数。

  • 符号—— –, -., , . , , , o , ^ , v , < , > , s , + , x , D , d , 1 , 2 , 3 , 4 , h , H , p , | , _
  • 颜色—— b、g、r、c、m、y、k、w

  现在,考虑执行以下代码 –

from pylab import *

x = linspace(-3, 3, 30)
y = x**2
plot(x, y, 'r.')
show()

  它绘制红点,如下所示 –

Matplotlib PyLab模块基本绘图
Matplotlib PyLab模块

  图可以叠加。只需使用多个绘图命令。使用 clf() 清除绘图。

from pylab import *
x = linspace(-3, 3, 30)
y = x**2
plot(x, y, 'r.')
show()

plot(x, sin(x))
plot(x, cos(x), 'r-')
plot(x, -sin(x), 'g--')
show()

  上面的代码行生成以下输出 –

Matplotlib PyLab模块基本绘图
Matplotlib PyLab模块

  推荐:Matplotlib教程

给文章评分

晓得博客,版权所有丨如未注明,均为原创
晓得博客 » Matplotlib PyLab模块

转载请保留链接:https://www.pythonthree.com/matplotlib-pylab-module/

Claude、Netflix、Midjourney、ChatGPT Plus、PS、Disney、Youtube、Office 365、多邻国Plus账号购买,ChatGPT API购买,优惠码XDBK,用户购买的时候输入优惠码可以打95折

Chatgpt-Plus注册购买共享账号
滚动至顶部