/[escript]/trunk/doc/examples/usersguide/poisson_matplotlib.py
ViewVC logotype

Diff of /trunk/doc/examples/usersguide/poisson_matplotlib.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2574 by gross, Mon Aug 3 09:09:20 2009 UTC revision 2600 by jfenwick, Fri Aug 7 04:47:49 2009 UTC
# Line 25  from esys.finley import Rectangle Line 25  from esys.finley import Rectangle
25  import numpy  import numpy
26  import matplotlib  import matplotlib
27    
28    matplotlib.use('agg')   #For interactive use, you can comment out this line
29    #It's just here to make testing easier
30    
31  import pylab  import pylab
 # generate domain:  
 mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20)  
 # define characteristic function of Gamma^D  
 x = mydomain.getX()  
 gammaD = whereZero(x[0])+whereZero(x[1])  
 # define PDE and get its solution u  
 mypde = Poisson(domain=mydomain)  
 mypde.setValue(f=1,q=gammaD)  
 u = mypde.getSolution()  
32    
33  # interpolate u to a matplotlib grid:  #Testing whether we have a late enough version of matplotlib
34  x_grid = numpy.linspace(0.,1.,50)  try:
35  y_grid = numpy.linspace(0.,1.,50)      matplotlib.mlab.griddata
36  x=mydomain.getX()[0].toListOfTuples()      # generate domain:
37  y=mydomain.getX()[1].toListOfTuples()      mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20)
38  z=interpolate(u,mydomain.getX().getFunctionSpace()).toListOfTuples()      # define characteristic function of Gamma^D
39  z_grid = matplotlib.mlab.griddata(x,y,z,xi=x_grid,yi=y_grid )      x = mydomain.getX()
40  # interpolate u to a rectangular grid:      gammaD = whereZero(x[0])+whereZero(x[1])
41  matplotlib.pyplot.contourf(x_grid, y_grid, z_grid, 5)      # define PDE and get its solution u
42  matplotlib.pyplot.savefig("u.png")      mypde = Poisson(domain=mydomain)
43  # uncommend this line if you want to interact with a plot window      mypde.setValue(f=1,q=gammaD)
44  matplotlib.pyplot.show()      u = mypde.getSolution()
45        
46        # interpolate u to a matplotlib grid:
47        x_grid = numpy.linspace(0.,1.,50)
48        y_grid = numpy.linspace(0.,1.,50)
49        x=mydomain.getX()[0].toListOfTuples()
50        y=mydomain.getX()[1].toListOfTuples()
51        z=interpolate(u,mydomain.getX().getFunctionSpace()).toListOfTuples()
52        z_grid = matplotlib.mlab.griddata(x,y,z,xi=x_grid,yi=y_grid )
53        # interpolate u to a rectangular grid:
54        matplotlib.pyplot.contourf(x_grid, y_grid, z_grid, 5)
55        matplotlib.pyplot.savefig("u.png")
56        # uncommend this line if you want to interact with a plot window
57        #matplotlib.pyplot.show()
58    
59    except AttributeError:
60        print "Your version of matplotlib does not provide the griddata method.\nSkipping example.\n"

Legend:
Removed from v.2574  
changed lines
  Added in v.2600

  ViewVC Help
Powered by ViewVC 1.1.26