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

Contents of /trunk/pyvisi_old/examples/arrowPlot.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: 2439 byte(s)
switched off pyvisi
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 @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 # the positions of the vectors
36 x = arange(20, typecode=Float)
37 y = arange(20, typecode=Float)
38
39 # the vector displacements
40 # (I may need to rethink how this works in the interface)
41 dx = arange(20, typecode=Float)
42 dy = arange(20, typecode=Float)
43
44 # set the positions randomly, and set the displacements to be the square of
45 # the positions
46 import random
47 random.seed()
48 for i in range(len(x)):
49 x[i] = random.random()
50 y[i] = random.random()
51 dx[i] = x[i]*x[i]
52 dy[i] = y[i]*y[i]
53
54 # example code for how a user would write a script in pyvisi
55 from esys.pyvisi import * # base level visualisation stuff
56 # import the objects to render the scene using the specific renderer
57 if ren_mod == "gnuplot":
58 from esys.pyvisi.renderers.gnuplot import * # gnuplot
59 elif ren_mod == "vtk":
60 from esys.pyvisi.renderers.vtk import * # vtk
61 else:
62 raise ValueError, "Unknown renderer module"
63
64 # define the scene object
65 # a Scene is a container for all of the kinds of things you want to put
66 # into your plot for instance, images, meshes, arrow/vector/quiver plots,
67 # contour plots, spheres etc.
68 scene = Scene()
69
70 # create an ArrowPlot object
71 plot = ArrowPlot(scene)
72
73 # add some helpful info to the plot
74 plot.title = 'Example 2D arrow/quiver/vector field plot'
75 plot.xlabel = 'x'
76 plot.ylabel = 'y'
77
78 # assign some data to the plot
79 plot.setData(x, y, dx, dy)
80
81 # render the scene to screen
82 scene.render(pause=True, interactive=True)
83
84 # save the scene out to file
85 scene.save(fname="arrowPlot.png", format=PngImage())
86
87 # vim: expandtab shiftwidth=4:
88

  ViewVC Help
Powered by ViewVC 1.1.26