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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 605 - (show annotations)
Mon Mar 20 07:16:27 2006 UTC (13 years, 6 months ago) by gross
File MIME type: text/x-python
File size: 2811 byte(s)
pyvisi with vtk runs noe on the altix
1 # $Id: scatterPlotExample.py,v 1.4 2005/03/07 04:16:19 paultcochrane Exp $
2
3 """
4 Example of a scatter plot in pyvisi
5 """
6
7 # what plotting method are we using?
8 method = 'pyvisi'
9
10 # set up some data to plot
11 from Numeric import *
12 import random
13
14 x = arange(30, typecode=Float)
15 y = arange(30, typecode=Float)
16
17 # make the data a bit more scatter-like by using random numbers
18 random.seed()
19 for i in range(len(x)):
20 x[i] = random.random()
21 y[i] = random.random()
22
23 # plot it using one of the three methods
24 if method == 'pyvisi':
25
26 # example code for how a user would write a script in pyvisi
27 from esys.pyvisi import * # base level visualisation stuff
28 #from esys.pyvisi.utils import * # pyvisi specific utils
29 # import the objects to render the scene using the specific renderer
30 from esys.pyvisi.renderers.gnuplot import * # gnuplot
31 #from esys.pyvisi.renderers.vtk import * # vtk
32
33 # define the scene object
34 # a Scene is a container for all of the kinds of things you want to put
35 # into your plot for instance, images, meshes, arrow/vector/quiver plots,
36 # contour plots, spheres etc.
37 scene = Scene()
38
39 # create a ScatterPlot object
40 plot = ScatterPlot(scene)
41
42 # add some helpful info to the plot
43 plot.title = 'Example 2D scatter plot'
44 plot.xlabel = 'x'
45 plot.ylabel = 'y'
46
47 # assign some data to the plot
48 plot.setData(x, y)
49
50 # render the scene to screen
51 scene.render(pause=True, interactive=True)
52
53 # save the scene out to file
54 plot.setData(x, y) # have to do this now because we've already
55 # render()ed the scene. This requirement will be
56 # removed in the future
57 scene.save(fname="scatterPlotExample.png", format=PngImage())
58 plot.setData(x, y) # have to do this now because we've already save()d
59 # the scene. This requirement will be removed in
60 # the future.
61 scene.save(fname="scatterPlotExample.ps", format=PsImage())
62
63 elif method == 'gnuplot':
64 #### original gnuplot code
65
66 import Gnuplot
67
68 # set the plot up
69 _gnuplot = Gnuplot.Gnuplot()
70 _gnuplot.title('Example 2D scatter plot')
71 _gnuplot.xlabel('x')
72 _gnuplot.ylabel('y')
73
74 # set up the data
75 _data = Gnuplot.Data(x, y, with='points pointtype 2')
76
77 # plot it
78 _gnuplot.plot(_data)
79
80 # set up to save to file
81 _gnuplot('set terminal png')
82 _gnuplot('set output \"scatterPlotExample.png\"')
83
84 # save it
85 _gnuplot.plot(_data)
86
87 raw_input('Press enter to continue...\n')
88
89 elif method == 'vtk':
90 #### original vtk code
91 print "vtk scatter plotting not yet implemented"
92
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