/[escript]/trunk/pyvisi/examples/scatterPlot3DExample.py
ViewVC logotype

Contents of /trunk/pyvisi/examples/scatterPlot3DExample.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 637 - (show annotations)
Thu Mar 23 10:55:31 2006 UTC (14 years, 2 months ago) by gross
File MIME type: text/x-python
File size: 3921 byte(s)
more copyright statements added
1 # $Id: scatterPlot3DExample.py,v 1.5 2005/03/07 05:23:37 paultcochrane Exp $
2
3 """
4 Example of plotting 3D scatter plots with pyvisi
5
6 @var __author__: name of author
7 @var __license__: licence agreement
8 @var __copyright__: copyrights
9 @var __url__: url entry point on documentation
10 @var __version__: version
11 @var __date__: date of the version
12 """
13
14 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
15 http://www.access.edu.au
16 Primary Business: Queensland, Australia"""
17 __license__="""Licensed under the Open Software License version 3.0
18 http://www.opensource.org/licenses/osl-3.0.php"""
19 __author__="Paul Cochrane"
20 __url__="http://www.iservo.edu.au/esys"
21 __version__="$Revision$"
22 __date__="$Date$"
23
24
25 # what plotting method are we using?
26 method = 'pyvisi'
27
28 # set up some data to plot
29 from Numeric import *
30 import random
31
32 # the x and y axes
33 x = arange(-2, 2, 0.2, typecode=Float)
34 y = arange(-3, 3, 0.2, typecode=Float)
35
36 # make the data a bit more scatter-like by using random numbers
37 random.seed()
38 for i in range(len(x)):
39 x[i] = x[i]*random.random()
40
41 for i in range(len(y)):
42 y[i] = y[i]*random.random()
43
44 # pick some interesting function to generate the data in the third dimension
45 # this is the one used in the matlab docs: z = x*exp(-x^2-y^2)
46 z = zeros((len(x),len(y)), typecode=Float)
47
48 # boy do *I* feel old fashioned writing it this way
49 # surely there's another way to do it: - something to do later
50 for i in range(len(x)):
51 for j in range(len(y)):
52 z[i,j] = exp(-x[i]*x[i] - y[j]*y[j])
53
54 # plot it with either gnuplot, vtk or pyvisi
55 if method == 'pyvisi':
56 #### pyvisi version of code
57
58 # import the general pyvisi stuff
59 from esys.pyvisi import *
60 # import the gnuplot overrides of the interface
61 from esys.pyvisi.renderers.gnuplot import *
62
63 # define a scene object
64 # a Scene is a container for all of the kinds of things you want to put
65 # into your plot, for instance, images, meshes, arrow/vector/quiver
66 # plots, contour plots, spheres etc.
67 scene = Scene()
68
69 # create a ScatterPlot3D object
70 plot = ScatterPlot3D(scene)
71
72 # add some helpful info to the plot
73 plot.title = 'Example 3D scatter plot'
74 plot.xlabel = 'x'
75 plot.ylabel = 'y'
76 plot.zlabel = 'z'
77
78 # assign the data to the plot
79 # this version assumes that we have x, then y, then z and that z is 2D
80 # and that x and y are 1D arrays
81 plot.setData(x,y,z)
82 # alternative syntax
83 #plot.setData(xData=x, yData=y, zData=z)
84 # or (but more confusing depending upon one's naming conventions)
85 #plot.setData(x=x, y=y, z=z)
86
87 # render the scene to screen
88 scene.render(pause=True, interactive=True)
89
90 # save the scene to file
91 plot.setData(x,y,z) # have to do this now because we've already
92 # render()ed the scene. This requirement will be
93 # removed in the future
94 scene.save(fname="scatterPlot3DExample.png", format=PngImage())
95 plot.setData(x,y,z) # have to do this now because we've already save()d
96 # the scene. This requirement will be removed in
97 # the future
98 scene.save(fname="scatterPlot3DExample.ps", format=PsImage())
99
100 elif method == 'gnuplot':
101 #### original gnuplot code
102
103 import Gnuplot
104
105 # set the plot up
106 _gnuplot = Gnuplot.Gnuplot()
107 _gnuplot.title('Example 3D scatter plot')
108 _gnuplot.xlabel('x')
109 _gnuplot.ylabel('y')
110 _gnuplot("set zlabel \'z\'")
111
112 # scatter plot, so set the data style to points
113 _gnuplot('set data style points')
114
115 # set up the data
116 _data = Gnuplot.GridData(z,x,y, binary=1)
117
118 _gnuplot.splot(_data)
119
120 raw_input('Press enter to continue...')
121
122 elif method == 'vtk':
123 print "vtk surface plotting not yet implemented"
124
125 else:
126 print "Eeek! What plotting method am I supposed to use???"
127
128 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26