Few weeks ago I tried some examples in Python after reading “Dive into Python”. My first feeling that python is easy to use and allows complex problems to be coded in few lines and minutes is now a certitude. Also there are a lot of libraries that are installed with two clicks and allows python to be used for all types of programming from sites to physics and bioengineering simulations.

Matplotlib is a library that allows easy drawing for series of numerical data in two or three dimensions.
Go to the official page and install it with just a few clicks. Be careful about the python version, there are a lot of differences between them (that is a minus for python).

For exemplification I have extended a previous program that generates pythagorean numbers. Here is the new program that plots points in 3D having as coordinates the pythgorean numbres:

#!/bin/env python

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

#the function to generate the pythgorean numbers(yield is a kind of return)
def pythagora(max):    
    a = 1
    while(a <= max):
        b = a+1
        while (b <= max):
            yield (b ** 2  - a ** 2) , (2 * a * b) , (a ** 2 + b ** 2)
            b += 1
        a += 1

fig = plt.figure()

ax = Axes3D(fig)
#in some versions may be: ax = fig.add_subplot(111, projection='3d')

#the arrays to hold the coordinates
x = []
y = []
z = []

#here is the iterator in action
for li in pythagora(15):    
    x.append(li[0])
    y.append(li[1])
    z.append(li[2])       

#the optional s and c are for dimension and color of the dots
ax.scatter( x , y, z, s=5, c='#00688B' )

#this is another type of graphic with lines:
#ax.plot( x , y,  z, c='c')

plt.show()

And here is the result:

You can rotate the graphic with the mouse. You can save it. You can magnify it, also it’s a bit tricky to point where you want in 3D (it’s easier in 2D).
I mentioned in the code the aditional “plot” method which draws lines from one point to the next in the array, but there are also charts and other types of displays and options.

UPDATE: Currently matplotlib does not work in python 3 and requires also the Numpy library to be installed. Try with the python 2.7 and corresponding numpy and matplotlib library.