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

Contents of /trunk/pyvisi_old/examples/arrowPlotExample.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 786 - (show annotations)
Tue Jul 25 04:58:05 2006 UTC (13 years, 2 months ago) by gross
File MIME type: text/x-python
File size: 2983 byte(s)
switched off pyvisi
1 # $Id: arrowPlotExample.py,v 1.3 2005/05/24 01:28:19 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 # what plotting method are we using?
26 method = 'pyvisi'
27
28 # set up some data to plot
29 from Numeric import *
30
31 # the positions of the vectors
32 x = arange(10, typecode=Float)
33 y = arange(10, typecode=Float)
34
35 # the vector displacements
36 # (I may need to rethink how this works in the interface)
37 dx = arange(10, typecode=Float)
38 dy = arange(10, typecode=Float)
39
40 # set the positions randomly, and set the displacements to be the square of
41 # the positions
42 import random
43 random.seed()
44 for i in range(len(x)):
45 x[i] = random.random()
46 y[i] = random.random()
47 dx[i] = x[i]*x[i]
48 dy[i] = y[i]*y[i]
49
50 # plot it using one of the three methods
51 if method == 'pyvisi':
52
53 # example code for how a user would write a script in pyvisi
54 from esys.pyvisi import * # base level visualisation stuff
55 #from esys.pyvisi.utils import * # pyvisi specific utils
56 # import the objects to render the scene using the specific renderer
57 from esys.pyvisi.renderers.gnuplot import * # gnuplot
58
59 # define the scene object
60 # a Scene is a container for all of the kinds of things you want to put
61 # into your plot for instance, images, meshes, arrow/vector/quiver plots,
62 # contour plots, spheres etc.
63 scene = Scene()
64
65 # create a LinePlot object
66 plot = ArrowPlot(scene)
67
68 # add some helpful info to the plot
69 plot.title = 'Example 2D arrow/quiver/vector field plot'
70 plot.xlabel = 'x'
71 plot.ylabel = 'y'
72
73 # assign some data to the plot
74 plot.setData(x, y, dx, dy)
75
76 # render the scene to screen
77 scene.render(pause=True, interactive=True)
78
79 # save the scene out to file
80 plot.setData(x, y, dx, dy) # have to do this now because we've already
81 # render()ed the scene. This requirement
82 # will be removed in the future
83 scene.save(fname="arrowPlotExample.png", format=PngImage())
84
85 elif method == 'vtk':
86 #### original vtk code
87
88 print "Sorry, the vtk interface hasn't been written yet."
89 elif method == 'plplot':
90 #### original plplot code
91
92 print "Sorry, the plplot interface hasn't been written yet."
93 else:
94 print "Eeek! What plotting method am I supposed to use???"
95
96 # vim: expandtab shiftwidth=4:
97

  ViewVC Help
Powered by ViewVC 1.1.26