# Contents of /trunk/pyvisi/test/python/gnuplot/meshPlot.py

Revision 604 - (show annotations)
Mon Mar 20 02:23:14 2006 UTC (13 years, 6 months ago) by gross
File MIME type: text/x-python
File size: 1202 byte(s)
```example cleanup
```
 1 # \$Id: meshPlot.py,v 1.1 2005/05/05 01:56:51 paultcochrane Exp \$ 2 3 """ 4 Example of plotting meshed surfaces with pyvisi 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 mesh plot') 31 _gnuplot.xlabel('x') 32 _gnuplot.ylabel('y') 33 _gnuplot('set zlabel \'z\'') 34 35 # this is a mesh 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 \"meshPlot.png\"') 47 48 # save it 49 _gnuplot.splot(_data) 50 51 raw_input('Press enter to continue...') 52