# Contents of /branches/stage3.0/doc/examples/usersguide/poisson_matplotlib.py

Revision 2584 - (show annotations)
Wed Aug 5 02:44:51 2009 UTC (9 years, 6 months ago) by jfenwick
File MIME type: text/x-python
File size: 1970 byte(s)
```Merging Lutz' doco changes to release
```
 1 2 ######################################################## 3 # 4 # Copyright (c) 2003-2009 by University of Queensland 5 # Earth Systems Science Computational Center (ESSCC) 6 7 # 8 # Primary Business: Queensland, Australia 9 # Licensed under the Open Software License version 3.0 10 11 # 12 ######################################################## 13 14 __copyright__="""Copyright (c) 2003-2009 by University of Queensland 15 Earth Systems Science Computational Center (ESSCC) 16 http://www.uq.edu.au/esscc 17 Primary Business: Queensland, Australia""" 18 __license__="""Licensed under the Open Software License version 3.0 19 20 __url__= 21 22 from esys.escript import * 23 from esys.escript.linearPDEs import Poisson 24 from esys.finley import Rectangle 25 import numpy 26 import matplotlib 27 28 import pylab 29 30 #Testing whether we have a late enough version of matplotlib 31 try: 32 matplotlib.mlab.griddata 33 # generate domain: 34 mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20) 35 # define characteristic function of Gamma^D 36 x = mydomain.getX() 37 gammaD = whereZero(x[0])+whereZero(x[1]) 38 # define PDE and get its solution u 39 mypde = Poisson(domain=mydomain) 40 mypde.setValue(f=1,q=gammaD) 41 u = mypde.getSolution() 42 43 # interpolate u to a matplotlib grid: 44 x_grid = numpy.linspace(0.,1.,50) 45 y_grid = numpy.linspace(0.,1.,50) 46 x=mydomain.getX()[0].toListOfTuples() 47 y=mydomain.getX()[1].toListOfTuples() 48 z=interpolate(u,mydomain.getX().getFunctionSpace()).toListOfTuples() 49 z_grid = matplotlib.mlab.griddata(x,y,z,xi=x_grid,yi=y_grid ) 50 # interpolate u to a rectangular grid: 51 matplotlib.pyplot.contourf(x_grid, y_grid, z_grid, 5) 52 matplotlib.pyplot.savefig("u.png") 53 # uncommend this line if you want to interact with a plot window 54 matplotlib.pyplot.show() 55 56 except AttributeError: 57 print "Your version of matplotlib does not provide the griddata method.\nSkipping example.\n"