Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 3203c6b5b5bf6c4bd2f69b939bc562d2 > files > 57

ipython-doc-0.10.2-1.fc14.noarch.rpm

"""Example of how to use pylab to plot parallel data.

The idea here is to run matplotlib is the same IPython session
as an ipython RemoteController client.  That way matplotlib
can be used to plot parallel data that is gathered using
RemoteController.  

To run this example, first start the IPython controller and 4
engines::

    ipcluster -n 4

Then start ipython in pylab mode::

    ipython -pylab
    
Then a simple "run parallel_pylab.ipy" in IPython will run the
example. 
"""

import numpy as N
from pylab import *
from IPython.kernel import client

# Get an IPython1 client
rc = client.MultiEngineClient()
rc.get_ids()
rc.activate()

# Create random arrays on the engines
# This is to simulate arrays that you have calculated in parallel
# on the engines.
# Anymore that length 10000 arrays, matplotlib starts to be slow
%px import numpy as N
%px x = N.random.standard_normal(10000)
%px y = N.random.standard_normal(10000)

%px print x[0:10]
%px print y[0:10]

# Bring back the data
x_local = rc.gather('x')
y_local = rc.gather('y')

# Make a scatter plot of the gathered data
plot(x_local, y_local,'ro')