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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 786 - (show annotations)
Tue Jul 25 04:58:05 2006 UTC (13 years, 1 month ago) by gross
File MIME type: text/x-python
File size: 3078 byte(s)
switched off pyvisi
1 # $Id: arrowPlot3D.py,v 1.6 2005/11/08 08:23:45 paultcochrane Exp $
2
3 """
4 Example of plotting a 3D vector field 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 = "vtk"
29 else:
30 ren_mod = sys.argv[1]
31
32 # set up some data to plot
33 from Numeric import *
34
35 dim = 10
36
37 # initialise the positions of the vectors
38 x = zeros((dim,dim), typecode=Float)
39 y = zeros((dim,dim), typecode=Float)
40 z = zeros((dim,dim), typecode=Float)
41
42 # initialise the vector displacements
43 # (I may need to rethink how this works in the interface)
44 dx = zeros((dim,dim), typecode=Float)
45 dy = zeros((dim,dim), typecode=Float)
46 dz = zeros((dim,dim), typecode=Float)
47
48 # set the positions randomly, and set the displacements to some smaller
49 # random number but of mean zero instead of distributed between 0 and 1
50 import random
51 random.seed()
52 for i in range(dim):
53 for j in range(dim):
54 x[i,j] = random.random()
55 y[i,j] = random.random()
56 z[i,j] = random.random()
57 dx[i,j] = (random.random()-0.5)/5.0
58 dy[i,j] = (random.random()-0.5)/5.0
59 dz[i,j] = (random.random()-0.5)/5.0
60
61 # example code for how a user would write a script in pyvisi
62 from esys.pyvisi import * # base level visualisation stuff
63 # import the objects to render the scene using the specific renderer
64 #from esys.pyvisi.renderers.gnuplot import * # gnuplot
65 if ren_mod == "vtk":
66 from esys.pyvisi.renderers.vtk import * # vtk
67 elif ren_mod == "povray":
68 from esys.pyvisi.renderers.povray import * # povray
69 else:
70 raise ValueError, "Unknown renderer module"
71
72 # define the scene object
73 # a Scene is a container for all of the kinds of things you want to put
74 # into your plot for instance, images, meshes, arrow/vector/quiver plots,
75 # contour plots, spheres etc.
76 scene = Scene()
77
78 # create a ArrowPlot3D object
79 plot = ArrowPlot3D(scene)
80
81 # add some helpful info to the plot
82 plot.title = 'Example 3D arrow/quiver/vector field plot'
83 plot.xlabel = 'x'
84 plot.ylabel = 'y'
85 plot.zlabel = 'z'
86
87 # assign some data to the plot
88 plot.setData(x, y, z, dx, dy, dz)
89
90 # render the scene to screen
91 scene.render(pause=True, interactive=True)
92
93 # save the scene out to file
94 scene.save(fname="arrowPlot3D.png", format=PngImage())
95
96 # plot data defined in a vtk file
97 plot.setData(fname='vel-0500.vtk', format='vtk-xml')
98
99 scene.render(pause=True, interactive=True)
100
101 # save this plot too
102 scene.save(fname="arrowPlot3Dvtk.png", format="png")
103
104 # vim: expandtab shiftwidth=4:
105

  ViewVC Help
Powered by ViewVC 1.1.26