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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 337 - (show annotations)
Mon Dec 12 01:57:07 2005 UTC (14 years, 5 months ago) by cochrane
File MIME type: text/x-python
File size: 2101 byte(s)
Initial merge of pyvisi into esys repository.
1 # $Id: arrowPlot2D.py,v 1.2 2005/11/08 08:23:45 paultcochrane Exp $
2
3 """
4 Example of plotting a vector field with pyvisi
5
6 This example uses 2D array inputs, which is sometimes easier for users.
7 """
8
9 import sys
10 numArgs = len(sys.argv)
11 if numArgs == 1:
12 ren_mod = "vtk"
13 else:
14 ren_mod = sys.argv[1]
15
16 # set up some data to plot
17 from Numeric import *
18
19 dim = 10
20
21 # initialise the positions of the vectors
22 x = zeros((dim,dim), typecode=Float)
23 y = zeros((dim,dim), typecode=Float)
24
25 # initialise the vector displacements
26 # (I may need to rethink how this works in the interface)
27 dx = zeros((dim,dim), typecode=Float)
28 dy = 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 dx[i,j] = (random.random()-0.5)/5.0
39 dy[i,j] = (random.random()-0.5)/5.0
40
41 # example code for how a user would write a script in pyvisi
42 from pyvisi import * # base level visualisation stuff
43 #from pyvisi.utils import * # pyvisi specific utils
44 # import the objects to render the scene using the specific renderer
45 if ren_mod == "vtk":
46 from pyvisi.renderers.vtk import *
47 elif ren_mod == "gnuplot":
48 from pyvisi.renderers.gnuplot import *
49 else:
50 raise ValueError, "Unknown renderer module"
51
52 # define the scene object
53 # a Scene is a container for all of the kinds of things you want to put
54 # into your plot for instance, images, meshes, arrow plots,
55 # contour plots, spheres etc.
56 scene = Scene()
57
58 # create a LinePlot object
59 plot = ArrowPlot(scene)
60
61 # add some helpful info to the plot
62 plot.title = 'Example 2D arrow/quiver/vector field plot'
63 plot.xlabel = 'x'
64 plot.ylabel = 'y'
65
66 # assign some data to the plot
67 plot.setData(x, y, dx, dy)
68
69 # render the scene to screen
70 scene.render(pause=True, interactive=True)
71
72 # save the scene out to file
73 scene.save(fname="arrowPlot2D.png", format=PngImage())
74
75 # vim: expandtab shiftwidth=4:
76

  ViewVC Help
Powered by ViewVC 1.1.26