/[escript]/trunk/pyvisi_old/examples/scatterPlot3D.py
ViewVC logotype

Contents of /trunk/pyvisi_old/examples/scatterPlot3D.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 786 - (show annotations)
Tue Jul 25 04:58:05 2006 UTC (13 years, 2 months ago) by gross
File MIME type: text/x-python
File size: 2812 byte(s)
switched off pyvisi
1 # $Id: scatterPlot3D.py,v 1.3 2005/11/08 08:23:45 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 import sys
26 numArgs = len(sys.argv)
27 if numArgs == 1:
28 ren_mod = "gnuplot"
29 else:
30 ren_mod = sys.argv[1]
31
32 # set up some data to plot
33 from Numeric import *
34 import random
35
36 # the x and y axes
37 x = arange(-2, 2, 0.2, typecode=Float)
38 y = arange(-3, 3, 0.2, typecode=Float)
39
40 # make the data a bit more scatter-like by using random numbers
41 random.seed()
42 for i in range(len(x)):
43 x[i] = x[i]*random.random()
44
45 for i in range(len(y)):
46 y[i] = y[i]*random.random()
47
48 # pick some interesting function to generate the data in the third dimension
49 # this is the one used in the matlab docs: z = x*exp(-x^2-y^2)
50 z = zeros((len(x),len(y)), typecode=Float)
51
52 # boy do *I* feel old fashioned writing it this way
53 # surely there's another way to do it: - something to do later
54 for i in range(len(x)):
55 for j in range(len(y)):
56 z[i,j] = exp(-x[i]*x[i] - y[j]*y[j])
57
58 # import the general pyvisi stuff
59 from esys.pyvisi import *
60 # import the renderer-specific overrides of the interface
61 if ren_mod == "gnuplot":
62 from esys.pyvisi.renderers.gnuplot import *
63 elif ren_mod == "vtk":
64 from esys.pyvisi.renderers.vtk import *
65 else:
66 raise ValueError, "Unknown renderer module"
67
68 # define a scene object
69 # a Scene is a container for all of the kinds of things you want to put
70 # into your plot, for instance, images, meshes, arrow/vector/quiver
71 # plots, contour plots, spheres etc.
72 scene = Scene()
73
74 # create a ScatterPlot3D object
75 plot = ScatterPlot3D(scene)
76
77 # add some helpful info to the plot
78 plot.title = 'Example 3D scatter plot'
79 plot.xlabel = 'x'
80 plot.ylabel = 'y'
81 plot.zlabel = 'z'
82
83 # assign the data to the plot
84 # this version assumes that we have x, then y, then z and that z is 2D
85 # and that x and y are 1D arrays
86 plot.setData(x,y,z)
87 # alternative syntax
88 #plot.setData(xData=x, yData=y, zData=z)
89 # or (but more confusing depending upon one's naming conventions)
90 #plot.setData(x=x, y=y, z=z)
91
92 # render the scene to screen
93 scene.render(pause=True, interactive=True)
94
95 # save the scene to file
96 scene.save(fname="scatterPlot3D.png", format=PngImage())
97
98 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26