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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 637 - (show annotations)
Thu Mar 23 10:55:31 2006 UTC (14 years, 2 months ago) by gross
File MIME type: text/x-python
File size: 2670 byte(s)
more copyright statements added
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 @var __author__: name of author
9 @var __license__: licence agreement
10 @var __copyright__: copyrights
11 @var __url__: url entry point on documentation
12 @var __version__: version
13 @var __date__: date of the version
14 """
15
16 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
17 http://www.access.edu.au
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __author__="Paul Cochrane"
22 __url__="http://www.iservo.edu.au/esys"
23 __version__="$Revision$"
24 __date__="$Date$"
25
26
27 import sys
28 numArgs = len(sys.argv)
29 if numArgs == 1:
30 ren_mod = "vtk"
31 else:
32 ren_mod = sys.argv[1]
33
34 # set up some data to plot
35 from Numeric import *
36
37 dim = 10
38
39 # initialise the positions of the vectors
40 x = zeros((dim,dim), typecode=Float)
41 y = zeros((dim,dim), typecode=Float)
42
43 # initialise the vector displacements
44 # (I may need to rethink how this works in the interface)
45 dx = zeros((dim,dim), typecode=Float)
46 dy = 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 dx[i,j] = (random.random()-0.5)/5.0
57 dy[i,j] = (random.random()-0.5)/5.0
58
59 # example code for how a user would write a script in pyvisi
60 from esys.pyvisi import * # base level visualisation stuff
61 # import the objects to render the scene using the specific renderer
62 if ren_mod == "vtk":
63 from esys.pyvisi.renderers.vtk import *
64 elif ren_mod == "gnuplot":
65 from esys.pyvisi.renderers.gnuplot import *
66 else:
67 raise ValueError, "Unknown renderer module"
68
69 # define the scene object
70 # a Scene is a container for all of the kinds of things you want to put
71 # into your plot for instance, images, meshes, arrow plots,
72 # contour plots, spheres etc.
73 scene = Scene()
74
75 # create a LinePlot object
76 plot = ArrowPlot(scene)
77
78 # add some helpful info to the plot
79 plot.title = 'Example 2D arrow/quiver/vector field plot'
80 plot.xlabel = 'x'
81 plot.ylabel = 'y'
82
83 # assign some data to the plot
84 plot.setData(x, y, dx, dy)
85
86 # render the scene to screen
87 scene.render(pause=True, interactive=True)
88
89 # save the scene out to file
90 scene.save(fname="arrowPlot2D.png", format=PngImage())
91
92 # vim: expandtab shiftwidth=4:
93

  ViewVC Help
Powered by ViewVC 1.1.26