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

Annotation of /trunk/pyvisi/examples/arrowPlot3D.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 605 - (hide annotations)
Mon Mar 20 07:16:27 2006 UTC (14 years, 3 months ago) by gross
File MIME type: text/x-python
File size: 2470 byte(s)
pyvisi with vtk runs noe on the altix
1 cochrane 337 # $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    
7     import sys
8     numArgs = len(sys.argv)
9     if numArgs == 1:
10     ren_mod = "vtk"
11     else:
12     ren_mod = sys.argv[1]
13    
14     # set up some data to plot
15     from Numeric import *
16    
17     dim = 10
18    
19     # initialise the positions of the vectors
20     x = zeros((dim,dim), typecode=Float)
21     y = zeros((dim,dim), typecode=Float)
22     z = zeros((dim,dim), typecode=Float)
23    
24     # initialise the vector displacements
25     # (I may need to rethink how this works in the interface)
26     dx = zeros((dim,dim), typecode=Float)
27     dy = zeros((dim,dim), typecode=Float)
28     dz = zeros((dim,dim), typecode=Float)
29    
30     # set the positions randomly, and set the displacements to some smaller
31     # random number but of mean zero instead of distributed between 0 and 1
32     import random
33     random.seed()
34     for i in range(dim):
35     for j in range(dim):
36     x[i,j] = random.random()
37     y[i,j] = random.random()
38     z[i,j] = random.random()
39     dx[i,j] = (random.random()-0.5)/5.0
40     dy[i,j] = (random.random()-0.5)/5.0
41     dz[i,j] = (random.random()-0.5)/5.0
42    
43     # example code for how a user would write a script in pyvisi
44 gross 605 from esys.pyvisi import * # base level visualisation stuff
45 cochrane 337 # import the objects to render the scene using the specific renderer
46 gross 605 #from esys.pyvisi.renderers.gnuplot import * # gnuplot
47 cochrane 337 if ren_mod == "vtk":
48 gross 605 from esys.pyvisi.renderers.vtk import * # vtk
49 cochrane 337 elif ren_mod == "povray":
50 gross 605 from esys.pyvisi.renderers.povray import * # povray
51 cochrane 337 else:
52     raise ValueError, "Unknown renderer module"
53    
54     # define the scene object
55     # a Scene is a container for all of the kinds of things you want to put
56     # into your plot for instance, images, meshes, arrow/vector/quiver plots,
57     # contour plots, spheres etc.
58     scene = Scene()
59    
60     # create a ArrowPlot3D object
61     plot = ArrowPlot3D(scene)
62    
63     # add some helpful info to the plot
64     plot.title = 'Example 3D arrow/quiver/vector field plot'
65     plot.xlabel = 'x'
66     plot.ylabel = 'y'
67     plot.zlabel = 'z'
68    
69     # assign some data to the plot
70     plot.setData(x, y, z, dx, dy, dz)
71    
72     # render the scene to screen
73     scene.render(pause=True, interactive=True)
74    
75     # save the scene out to file
76     scene.save(fname="arrowPlot3D.png", format=PngImage())
77    
78     # plot data defined in a vtk file
79     plot.setData(fname='vel-0500.vtk', format='vtk-xml')
80    
81     scene.render(pause=True, interactive=True)
82    
83     # save this plot too
84     scene.save(fname="arrowPlot3Dvtk.png", format="png")
85    
86     # vim: expandtab shiftwidth=4:
87    

  ViewVC Help
Powered by ViewVC 1.1.26