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

revision 2574 by gross, Mon Aug 3 09:09:20 2009 UTC revision 2578 by jfenwick, Tue Aug 4 04:05:36 2009 UTC
# Line 26  import numpy Line 26  import numpy
26  import matplotlib  import matplotlib
27
28  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()
# define PDE and get its solution u
mypde = Poisson(domain=mydomain)
u = mypde.getSolution()
29
30  # interpolate u to a matplotlib grid:  #Testing whether we have a late enough version of matplotlib
31  x_grid = numpy.linspace(0.,1.,50)  try:
32  y_grid = numpy.linspace(0.,1.,50)      matplotlib.mlab.griddata
33  x=mydomain.getX()[0].toListOfTuples()      # generate domain:
34  y=mydomain.getX()[1].toListOfTuples()      mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20)
35  z=interpolate(u,mydomain.getX().getFunctionSpace()).toListOfTuples()      # define characteristic function of Gamma^D
36  z_grid = matplotlib.mlab.griddata(x,y,z,xi=x_grid,yi=y_grid )      x = mydomain.getX()
37  # interpolate u to a rectangular grid:      gammaD = whereZero(x[0])+whereZero(x[1])
38  matplotlib.pyplot.contourf(x_grid, y_grid, z_grid, 5)      # define PDE and get its solution u
39  matplotlib.pyplot.savefig("u.png")      mypde = Poisson(domain=mydomain)
40  # uncommend this line if you want to interact with a plot window      mypde.setValue(f=1,q=gammaD)
41  matplotlib.pyplot.show()      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"

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