numpy,scipy,matplotlib和pylab之间的混淆

goF*_*ard 130 python numpy matplotlib scipy

Numpy,scipy,matplotlib和pylab是使用python进行科学计算的常用术语.

我只是学习了一下pylab,我感到很困惑.每当我想导入numpy时,我总能做到:

import numpy as np
Run Code Online (Sandbox Code Playgroud)

我只是考虑,一旦我做了

from pylab import *
Run Code Online (Sandbox Code Playgroud)

numpy也将被导入(带np别名).所以基本上第二个与第一个相比做了更多的事情.

我想问几件事:

  1. 是不是pylab只是numpy,scipy和matplotlib的包装器?
  2. 由于np是pylab中的numpy别名,pylab中的scipy和matplotlib别名是什么?(据我所知,plt是matplotlib.pyplot的别名,但我不知道matplotlib本身的别名)

Ben*_*ier 126

  1. 不,pylabmatplotlib(in matplotlib.pylab)的一部分,并试图为您提供类似MatLab的环境.matplotlib有许多依赖项,其中包括numpy它在公共别名下导入的依赖项np.scipy不是依赖matplotlib.

  2. 如果运行ipython --pylab自动导入,则会将所有符号matplotlib.pylab放入全局范围.就像你写的那样numpynp别名下导入.别名matplotlib下可以使用符号mpl.

  • @Benjamin Bannier这是什么 - http://wiki.scipy.org/PyLab?这让我很困惑. (9认同)

Fel*_*ida 10

Scipy和numpy是科学项目,其目的是为python带来高效和快速的数值计算.

Matplotlib是python绘图库的名称.

Pyplot是matplotlib的交互式api,主要用于像jupyter这样的笔记本电脑.你通常这样使用它:import matplotlib.pyplot as plt.

Pylab与pyplot相同,但具有额外功能(目前不鼓励使用它).

  • 粗略地说,pylab = pyplot + numpy

在这里查看更多信息:Matplotlib,Pylab,Pyplot等:这些和何时使用它们之间的区别是什么?

  • [直接在 matplotlib 的网站上发布的另一个示例](https://matplotlib.org/faq/usage_faq.html#matplotlib-pyplot-and-pylab-how-are-they-related) “Matplotlib、pyplot 和 pylab:它们如何相关吗?`Matplotlib` 是**整个包**;`matplotlib.pyplot` 是一个模块 **在 matplotlib** 中;而 `pylab` 是一个模块,**与 matplotlib 一起安装。**” (2认同)