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

查看:303
本文介绍了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调用图将自动创建必要的图形和轴以实现所需的图.设置标题后,该标题将自动设置为当前轴对象:

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界面方便了交互式计算和绘图,因为它最大程度地减少了键入.请注意,这是将ipython shell与-pylab选项一起使用所获得的,该选项从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天全站免登陆