pylab 和 pyplot 有什么区别? [英] What is the difference between pylab and pyplot?

查看:19
本文介绍了pylab 和 pyplot 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么区别matplotlib.pyplot 和 matplotlib.pylab?

What is the difference between matplotlib.pyplot and matplotlib.pylab?

哪个更适合什么用途?

我有点困惑,因为它似乎独立于我导入的,我可以做同样的事情.我错过了什么?

I am a little confused, because it seems like independent from which I import, I can do the same things. What am I missing?

推荐答案

此措辞不再出现在文档中.

现在不鼓励使用 pylab 导入,建议大多数非交互式使用使用 OO 接口.

Use of the pylab import is now discouraged and the OO interface is recommended for most non-interactive usage.

文档,重点是我的:

Matplotlib 是整个包;pylab 是 matplotlib 中的一个模块,它与 matplotlib 一起安装;而 matplotlib.pyplot 是 matplotlib 中的一个模块.

Matplotlib is the whole package; pylab is a module in matplotlib that gets installed alongside matplotlib; and matplotlib.pyplot is a module in matplotlib.

Pyplot 为 matplotlib 中的底层绘图库提供状态机接口.这意味着图形和轴是隐式和自动创建的,以实现所需的绘图.例如,从 pyplot 调用 plot 将自动创建必要的图形和轴以实现所需的绘图.设置标题会自动将该标题设置为当前坐标区对象:

Pyplot provides the state-machine interface to the underlying plotting library in matplotlib. This means that figures and axes are implicitly and automatically created to achieve the desired plot. For example, calling plot from pyplot will automatically create the necessary figure and axes to achieve the desired plot. Setting a title will then automatically set that title to the current axes object:

Pylab 在单个命名空间中结合了 pyplot 功能(用于绘图)和 numpy 功能(用于数学和处理数组),使该命名空间(或环境)更像 MATLAB.例如,您可以像在 MATLAB 中一样调用 sin 和 cos 函数,并且拥有 pyplot 的所有功能.

Pylab combines the pyplot functionality (for plotting) with the numpy functionality (for mathematics and for working with arrays) in a single namespace, making that namespace (or environment) even more MATLAB-like. For example, one can call the sin and cos functions just like you could in MATLAB, as well as having all the features of pyplot.

pyplot 界面通常首选用于非交互式绘图(即脚本).pylab 界面便于交互式计算和绘图,因为它最大限度地减少了输入.请注意,如果您使用带有 -pylab 选项的 ipython shell,这就是您得到的结果,该选项从 pylab 导入所有内容并使绘图完全交互.

The pyplot interface is generally preferred for non-interactive plotting (i.e., scripting). The pylab interface is convenient for interactive calculations and plotting, as it minimizes typing. Note that this is what you get if you use the ipython shell with the -pylab option, which imports everything from pylab and makes plotting fully interactive.

这篇关于pylab 和 pyplot 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆