# Contents of /trunk/pyvisi/examples/arrowPlotExample2.py

Revision 337 - (show annotations)
Mon Dec 12 01:57:07 2005 UTC (14 years, 5 months ago) by cochrane
File MIME type: text/x-python
File size: 2621 byte(s)
```Initial merge of pyvisi into esys repository.
```
 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 9 # what plotting method are we using? 10 method = 'pyvisi' 11 12 # set up some data to plot 13 from Numeric import * 14 15 dim = 10 16 17 # initialise the positions of the vectors 18 x = zeros((dim,dim), typecode=Float) 19 y = zeros((dim,dim), typecode=Float) 20 21 # initialise the vector displacements 22 # (I may need to rethink how this works in the interface) 23 dx = zeros((dim,dim), typecode=Float) 24 dy = zeros((dim,dim), typecode=Float) 25 26 # set the positions randomly, and set the displacements to some smaller 27 # random number but of mean zero instead of distributed between 0 and 1 28 import random 29 random.seed() 30 for i in range(dim): 31 for j in range(dim): 32 x[i,j] = random.random() 33 y[i,j] = random.random() 34 dx[i,j] = (random.random()-0.5)/5.0 35 dy[i,j] = (random.random()-0.5)/5.0 36 37 # plot it using one of the three methods 38 if method == 'pyvisi': 39 40 # example code for how a user would write a script in pyvisi 41 from pyvisi import * # base level visualisation stuff 42 #from pyvisi.utils import * # pyvisi specific utils 43 # import the objects to render the scene using the specific renderer 44 from pyvisi.renderers.gnuplot import * # gnuplot 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 a LinePlot 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 plot.setData(x, y, dx, dy) # have to do this now because we've already 68 # render()ed the scene. This requirement 69 # will be removed in the future 70 scene.save(fname="arrowPlotExample2.png", format=PngImage()) 71 72 elif method == 'vtk': 73 #### original vtk code 74 75 print "Sorry, the vtk interface hasn't been written yet." 76 elif method == 'plplot': 77 #### original plplot code 78 79 print "Sorry, the plplot interface hasn't been written yet." 80 else: 81 print "Eeek! What plotting method am I supposed to use???" 82 83 # vim: expandtab shiftwidth=4: 84