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

Contents of /trunk/pyvisi_old/examples/arrowPlotExample2.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: 3244 byte(s)
switched off pyvisi
1 # $Id: arrowPlotExample2.py,v 1.2 2005/05/24 01:30:36 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 # what plotting method are we using?
28 method = 'pyvisi'
29
30 # set up some data to plot
31 from Numeric import *
32
33 dim = 10
34
35 # initialise the positions of the vectors
36 x = zeros((dim,dim), typecode=Float)
37 y = zeros((dim,dim), typecode=Float)
38
39 # initialise the vector displacements
40 # (I may need to rethink how this works in the interface)
41 dx = zeros((dim,dim), typecode=Float)
42 dy = zeros((dim,dim), typecode=Float)
43
44 # set the positions randomly, and set the displacements to some smaller
45 # random number but of mean zero instead of distributed between 0 and 1
46 import random
47 random.seed()
48 for i in range(dim):
49 for j in range(dim):
50 x[i,j] = random.random()
51 y[i,j] = random.random()
52 dx[i,j] = (random.random()-0.5)/5.0
53 dy[i,j] = (random.random()-0.5)/5.0
54
55 # plot it using one of the three methods
56 if method == 'pyvisi':
57
58 # example code for how a user would write a script in pyvisi
59 from esys.pyvisi import * # base level visualisation stuff
60 #from esys.pyvisi.utils import * # pyvisi specific utils
61 # import the objects to render the scene using the specific renderer
62 from esys.pyvisi.renderers.gnuplot import * # gnuplot
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 a LinePlot 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 plot.setData(x, y, dx, dy) # have to do this now because we've already
86 # render()ed the scene. This requirement
87 # will be removed in the future
88 scene.save(fname="arrowPlotExample2.png", format=PngImage())
89
90 elif method == 'vtk':
91 #### original vtk code
92
93 print "Sorry, the vtk interface hasn't been written yet."
94 elif method == 'plplot':
95 #### original plplot code
96
97 print "Sorry, the plplot interface hasn't been written yet."
98 else:
99 print "Eeek! What plotting method am I supposed to use???"
100
101 # vim: expandtab shiftwidth=4:
102

  ViewVC Help
Powered by ViewVC 1.1.26