Matplotlib is the de facto 2D plotting interface for python, thanks to its integration with ipython. It produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms (Tk, GTK, Qt, ...).
Matplotlib comes with two programming interfaces:
In [1]:
from scipy.misc import lena
img = lena()
In [2]:
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(1,2,1)
ax2 = fig.add_subplot(1,2,2)
ax1.imshow(img, cmap="gray")
ax2.hist(img.flat, 256)
fig.show()
There are plenty of plots available among them:
Of course many other types of plots are possible, the easiest is probably to look at the gallery
Some other interesing commands are:
Overall, this lacks interactivity !
The pylab interface offers a scripting user interface close to the one of Matlab, especially when integrated into ipython.
One can select the backend at runtime like %pylab inline or %pylab qt4
The pylab interface makes common matplotlib interface for the former action as simple as:
This is useful for prototyping and create small scripts. I recommand you to use the %pylab in ipython
In [3]:
%pylab inline
In [4]:
x = numpy.linspace(-5,5,500)
y = numpy.exp(-x*x)
plot(x,y,label="gaussian")
legend()
Out[4]:
Warning, this "ease of use" comes a price:
The authors are aware of this "weakness" ... but this is the price to mimic matlab. Anyway, by using matlab you would have to by the same amount of memory for your computer in addition to the license :þ
If you run ipython --pylab what happends ?
Python performs a *from pylab import **
In [5]:
matplotlib.pylab??
Scarry, no ?
Use the pylab interface for prototyping interactively and convert it to the pyplot interface when writing the application.
Visualization may be OK, but Matlab provides me with all libraries I have dreamt of. Aren't they available from Python ? Yes they are available within SciPy
In [ ]: