I have always been confused about matplotlib, pyplot, and pylab. Actually, I know that matplotlib is a Python library for (scientific) plotting. It provides a lot of plotting functions, from simple graphs to complex ones. But I hadn’t known what pyplot ans pylab were until I read this article.
pyplot is just a wrapper module to provide a Matlab-style interface to matplotlib. Many plotting functions in Matlab are provided by pyplot with the same names and arguments. This will ease the process of moving from Matlab to Python for scientific computation.
pylab is basically a mode in which pyplot and numpy are imported in a single namespace, thus making the Python working environment very similar to Matlab. By importing pylab:
from pylab import *
we can use Matlab-style commands like:
x = arange(0, 10, 0.2)
y = sin(x)
iPython shell provides a switch (-pylab) which automatically imports numpy as np and pyplot as plt. The above lines can thus be written as:
x = np.arange(0, 10, 0.2)
y = np.sin(x)