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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 337 - (show annotations)
Mon Dec 12 01:57:07 2005 UTC (13 years, 9 months ago) by cochrane
File MIME type: text/x-python
File size: 2067 byte(s)
Initial merge of pyvisi into esys repository.
1 # $Id: randomLinePlot.py,v 1.2 2005/11/10 08:37:41 paultcochrane Exp $
2
3 """
4 Example of plotting lines with pyvisi
5
6 This time using a large set of random numbers as input and can be used to
7 stress test the underlying renderer module.
8 """
9
10 import sys
11 numArgs = len(sys.argv)
12 if numArgs == 1:
13 ren_mod = "vtk"
14 else:
15 ren_mod = sys.argv[1]
16
17 # set up some data to plot
18 from Numeric import *
19 import random
20
21 numPoints = 100000
22 x = arange(numPoints, typecode=Float)
23 y = zeros(numPoints, typecode=Float)
24 random.seed()
25 for i in range(numPoints):
26 y[i] = random.random()
27
28 y2 = 2*y
29
30 # example code for how a user would write a script in pyvisi
31 from pyvisi import * # base level visualisation stuff
32 # import the objects to render the scene using the specific renderer
33 if ren_mod == "gnuplot":
34 from pyvisi.renderers.gnuplot import * # gnuplot
35 elif ren_mod == "vtk":
36 from pyvisi.renderers.vtk import * # vtk
37 elif ren_mod == "plplot":
38 from pyvisi.renderers.plplot import * # plplot
39 else:
40 raise ValueError, "Unknown renderer module"
41
42 # define the scene object
43 # a Scene is a container for all of the kinds of things you want to put
44 # into your plot for instance, images, meshes, arrow/vector/quiver plots,
45 # contour plots, spheres etc.
46 scene = Scene()
47
48 # create a LinePlot object
49 plot = LinePlot(scene)
50
51 # add some helpful info to the plot
52 plot.title = 'Example of a 2D line plot of random numbers'
53 plot.xlabel = 'x'
54 plot.ylabel = 'y'
55 plot.linestyle = 'lines'
56
57 # assign some data to the plot
58 plot.setData(range(numPoints), y)
59
60 # render the scene to screen
61 scene.render(pause=True, interactive=True)
62 # save the scene out to file
63 scene.save(fname="randomLinePlot1.png", format="png")
64
65 plot.title = 'Another example of a 2D line plot of random numbers'
66 plot.xlabel = 'x'
67 plot.ylabel = 'y'
68 plot.linestyle = 'lines'
69
70 plot.setData(range(numPoints), y2)
71
72 # render the scene to screen
73 scene.render(pause=True, interactive=True)
74 # save the scene out to file
75 scene.save(fname="randomLinePlot2.png", format="png")
76
77 # vim: expandtab shiftwidth=4:
78

  ViewVC Help
Powered by ViewVC 1.1.26