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

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