Reputation: 131278
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?
Upvotes: 3
Views: 3309
Reputation: 6767
From the official documentation:
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.
Note that pylab only imports from the top numpy namespace. Therefore, this will worK
import numpy
numpy.array # works
numpy.distutils # finds a module
And this will not
import pylab
pylab.array # works, is actually numpy array
pylab.distutils # gives an error
Upvotes: 4