##// END OF EJS Templates
Merge pull request #564 from takluyver/docs--args...
Merge pull request #564 from takluyver/docs--args Command line args in docs

File last commit:

r3670:45e272d0
r4200:2952bd3b merge
Show More
plotting_frontend.py
59 lines | 1.5 KiB | text/x-python | PythonLexer
MinRK
updates to docs and examples
r3670 """An example of how to use IPython1 for plotting remote parallel data
MinRK
remove kernel examples already ported to newparallel
r3675 The two files plotting_frontend.py and plotting_backend.py go together.
MinRK
updates to docs and examples
r3670
To run this example, first start the IPython controller and 4
engines::
MinRK
remove kernel examples already ported to newparallel
r3675 ipclusterz start -n 4
MinRK
updates to docs and examples
r3670
Then start ipython in pylab mode::
ipython -pylab
MinRK
remove kernel examples already ported to newparallel
r3675 Then a simple "run plotting_frontend.py" in IPython will run the
MinRK
updates to docs and examples
r3670 example. When this is done, all the variables (such as number, downx, etc.)
are available in IPython, so for example you can make additional plots.
"""
import numpy as N
from pylab import *
MinRK
remove kernel examples already ported to newparallel
r3675 from IPython.parallel import Client
MinRK
updates to docs and examples
r3670
MinRK
remove kernel examples already ported to newparallel
r3675 # Connect to the cluster
rc = Client()
view = rc[:]
MinRK
updates to docs and examples
r3670
# Run the simulation on all the engines
MinRK
remove kernel examples already ported to newparallel
r3675 view.run('plotting_backend.py')
MinRK
updates to docs and examples
r3670
MinRK
remove kernel examples already ported to newparallel
r3675 # Bring back the data. These are all AsyncResult objects
number = view.pull('number')
d_number = view.pull('d_number')
downx = view.gather('downx')
downy = view.gather('downy')
downpx = view.gather('downpx')
downpy = view.gather('downpy')
MinRK
updates to docs and examples
r3670
MinRK
remove kernel examples already ported to newparallel
r3675 # but we can still iterate through AsyncResults before they are done
MinRK
updates to docs and examples
r3670 print "number: ", sum(number)
print "downsampled number: ", sum(d_number)
MinRK
remove kernel examples already ported to newparallel
r3675
MinRK
updates to docs and examples
r3670 # Make a scatter plot of the gathered data
# These calls to matplotlib could be replaced by calls to pygist or
# another plotting package.
figure(1)
MinRK
remove kernel examples already ported to newparallel
r3675 # wait for downx/y
downx = downx.get()
downy = downy.get()
MinRK
updates to docs and examples
r3670 scatter(downx, downy)
xlabel('x')
ylabel('y')
figure(2)
MinRK
remove kernel examples already ported to newparallel
r3675 # wait for downpx/y
downpx = downpx.get()
downpy = downpy.get()
MinRK
updates to docs and examples
r3670 scatter(downpx, downpy)
xlabel('px')
ylabel('py')
show()