“pylab"和“pylab"有什么区别?和"matplotlib.pyplot"? [英] What is a difference between "pylab" and "matplotlib.pyplot"?
问题描述
我尝试使用MatPlotLib,我意识到可以用两种不同的方式导入它,并且在两种情况下都可以工作(以相同的方式):将pylab导入为p
或 import matplotlib.pyplot 作为 p
.
I try to use MatPlotLib and I have realized that can import it in two different ways and in both cases it works (in the same way): import pylab as p
or import matplotlib.pyplot as p
.
那么,我的问题是这两种方式有什么区别?
So, my question is what is the difference between these two ways?
推荐答案
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.
请注意,pylab仅从顶部的numpy名称空间导入.因此,这会很重要
Note that pylab only imports from the top numpy namespace. Therefore, this will worK
import numpy
numpy.array # works
numpy.distutils # finds a module
这不会
import pylab
pylab.array # works, is actually numpy array
pylab.distutils # gives an error
这篇关于“pylab"和“pylab"有什么区别?和"matplotlib.pyplot"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!