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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 337 - (show annotations)
Mon Dec 12 01:57:07 2005 UTC (13 years, 9 months ago) by cochrane
File MIME type: text/x-python
File size: 1816 byte(s)
Initial merge of pyvisi into esys repository.
1 # $Id: arrowPlot.py,v 1.4 2005/11/08 08:23:45 paultcochrane Exp $
2
3 """
4 Example of plotting a 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 # the positions of the vectors
18 x = arange(20, typecode=Float)
19 y = arange(20, typecode=Float)
20
21 # the vector displacements
22 # (I may need to rethink how this works in the interface)
23 dx = arange(20, typecode=Float)
24 dy = arange(20, typecode=Float)
25
26 # set the positions randomly, and set the displacements to be the square of
27 # the positions
28 import random
29 random.seed()
30 for i in range(len(x)):
31 x[i] = random.random()
32 y[i] = random.random()
33 dx[i] = x[i]*x[i]
34 dy[i] = y[i]*y[i]
35
36 # example code for how a user would write a script in pyvisi
37 from pyvisi import * # base level visualisation stuff
38 # import the objects to render the scene using the specific renderer
39 if ren_mod == "gnuplot":
40 from pyvisi.renderers.gnuplot import * # gnuplot
41 elif ren_mod == "vtk":
42 from pyvisi.renderers.vtk import * # vtk
43 else:
44 raise ValueError, "Unknown renderer module"
45
46 # define the scene object
47 # a Scene is a container for all of the kinds of things you want to put
48 # into your plot for instance, images, meshes, arrow/vector/quiver plots,
49 # contour plots, spheres etc.
50 scene = Scene()
51
52 # create an ArrowPlot object
53 plot = ArrowPlot(scene)
54
55 # add some helpful info to the plot
56 plot.title = 'Example 2D arrow/quiver/vector field plot'
57 plot.xlabel = 'x'
58 plot.ylabel = 'y'
59
60 # assign some data to the plot
61 plot.setData(x, y, dx, dy)
62
63 # render the scene to screen
64 scene.render(pause=True, interactive=True)
65
66 # save the scene out to file
67 scene.save(fname="arrowPlot.png", format=PngImage())
68
69 # vim: expandtab shiftwidth=4:
70

  ViewVC Help
Powered by ViewVC 1.1.26