/[escript]/trunk/pyvisi/test/python/gnuplot/surfacePlot.py
ViewVC logotype

Contents of /trunk/pyvisi/test/python/gnuplot/surfacePlot.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 604 - (show annotations)
Mon Mar 20 02:23:14 2006 UTC (13 years, 7 months ago) by gross
File MIME type: text/x-python
File size: 1226 byte(s)
example cleanup
1 # $Id: surfacePlot.py,v 1.2 2005/11/08 07:24:22 paultcochrane Exp $
2
3 """
4 Example of plotting surfaces
5 """
6
7 # set up some data to plot
8 from Numeric import *
9
10 # the x and y axes
11 x = arange(-2,2,0.2, typecode=Float)
12 y = arange(-2,3,0.2, typecode=Float)
13
14 # pick some interesting function to generate the data in the third dimension
15 # this is the one used in the matlab docs: z = x*exp(-x^2-y^2)
16 z = zeros((len(x),len(y)), typecode=Float)
17
18 # boy do *I* feel old fashioned writing it this way
19 # surely there's another way to do it: - something to do later
20 for i in range(len(x)):
21 for j in range(len(y)):
22 z[i,j] = x[i]*exp(-x[i]*x[i] - y[j]*y[j])
23
24 #### original gnuplot code
25
26 import Gnuplot
27
28 # set the plot up
29 _gnuplot = Gnuplot.Gnuplot()
30 _gnuplot.title('Example surface plot')
31 _gnuplot.xlabel('x')
32 _gnuplot.ylabel('y')
33 _gnuplot('set zlabel \'z\'')
34
35 # this is a surface plot, so...
36 _gnuplot('set surface')
37 _gnuplot('set data style lines')
38
39 # set up the data
40 _data = Gnuplot.GridData(z,x,y, binary=1)
41
42 _gnuplot.splot(_data)
43
44 # set up to save to file
45 _gnuplot('set terminal png')
46 _gnuplot('set output \"surfacePlot.png\"')
47
48 # save it
49 _gnuplot.splot(_data)
50
51 raw_input('Press enter to continue...')
52
53 # vim: expandtab shiftwidth=4:
54

  ViewVC Help
Powered by ViewVC 1.1.26