SciPy is a library of scientific tools for Python. It has a large user base, and is growing rapidly.
Before continuing, ensure that SciPy is installed. Prerequisites are Python, the Numeric module, and (for plt) wxPython. On the Windows platform, installation is quite easy with self-installing exe packages. On Linux, it's no more complicated that the usual package. In some cases, rpm and deb packages exist. ( I didn't use them.)
You really should read the short
plotting tutorial, one of several
tutorials available.
There are at least three plotting routines available for scipy. Since
plt is
available for both Unix and Windows, I'll discuss that.
Here's a typical example of how to display data with 'plt':
# import the necessary modules
>>> import gui_thread
<wxPython imported>
>>> from scipy import *
>>> from scipy import plt
# create some data to plot
>>> x = [1,2,3,4]
>>> y = [1,4,9,16]
>>> plt.plot(x,y)
[ a graphics window should appear ]
# now add some titles
>>> plt.xtitle('x axis')
>>> plt.ytitle('y axis')
(You change also add text from the Titles menu; or change text, fonts, and sizes by right-clicking on the labels and title. You can zoom by dragging with the left button, and autozoom out with a right-click.)
The following generates a "image plot" or "density plot":
>>> x=(arange(100.)-50)/2.
>>> y=(arange(100.)-50)/2.
>>> r = sqrt(x[:,NewAxis]**2+y**2)
>>> z = r**2
>>> plt.image(z)
You'll notice that the image is banded, while the z values are smoothly
varying. That is because the default colormap ("grey" or "gray") has values
ranging from 0 to 255, while the range of our data is from 0 to 1250:
>>> print min(ravel(z)), max(ravel(z))
This can be corrected by autoscaling the data. Use imagesc instead of image:
>>> plt.imagesc(z)
Again, please see the
short
plotting tutorial and
general tutorials.
Feel free to e-mail me with any questions about this document.