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

Contents of /trunk/pyvisi_old/examples/scatterPlotExample.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: 3419 byte(s)
switched off pyvisi
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 @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 import random
31
32 x = arange(30, typecode=Float)
33 y = arange(30, typecode=Float)
34
35 # make the data a bit more scatter-like by using random numbers
36 random.seed()
37 for i in range(len(x)):
38 x[i] = random.random()
39 y[i] = random.random()
40
41 # plot it using one of the three methods
42 if method == 'pyvisi':
43
44 # example code for how a user would write a script in pyvisi
45 from esys.pyvisi import * # base level visualisation stuff
46 #from esys.pyvisi.utils import * # pyvisi specific utils
47 # import the objects to render the scene using the specific renderer
48 from esys.pyvisi.renderers.gnuplot import * # gnuplot
49 #from esys.pyvisi.renderers.vtk import * # vtk
50
51 # define the scene object
52 # a Scene is a container for all of the kinds of things you want to put
53 # into your plot for instance, images, meshes, arrow/vector/quiver plots,
54 # contour plots, spheres etc.
55 scene = Scene()
56
57 # create a ScatterPlot object
58 plot = ScatterPlot(scene)
59
60 # add some helpful info to the plot
61 plot.title = 'Example 2D scatter plot'
62 plot.xlabel = 'x'
63 plot.ylabel = 'y'
64
65 # assign some data to the plot
66 plot.setData(x, y)
67
68 # render the scene to screen
69 scene.render(pause=True, interactive=True)
70
71 # save the scene out to file
72 plot.setData(x, y) # have to do this now because we've already
73 # render()ed the scene. This requirement will be
74 # removed in the future
75 scene.save(fname="scatterPlotExample.png", format=PngImage())
76 plot.setData(x, y) # have to do this now because we've already save()d
77 # the scene. This requirement will be removed in
78 # the future.
79 scene.save(fname="scatterPlotExample.ps", format=PsImage())
80
81 elif method == 'gnuplot':
82 #### original gnuplot code
83
84 import Gnuplot
85
86 # set the plot up
87 _gnuplot = Gnuplot.Gnuplot()
88 _gnuplot.title('Example 2D scatter plot')
89 _gnuplot.xlabel('x')
90 _gnuplot.ylabel('y')
91
92 # set up the data
93 _data = Gnuplot.Data(x, y, with='points pointtype 2')
94
95 # plot it
96 _gnuplot.plot(_data)
97
98 # set up to save to file
99 _gnuplot('set terminal png')
100 _gnuplot('set output \"scatterPlotExample.png\"')
101
102 # save it
103 _gnuplot.plot(_data)
104
105 raw_input('Press enter to continue...\n')
106
107 elif method == 'vtk':
108 #### original vtk code
109 print "vtk scatter plotting not yet implemented"
110
111 else:
112 print "Eeek! What plotting method am I supposed to use???"
113
114 # vim: expandtab shiftwidth=4:
115

  ViewVC Help
Powered by ViewVC 1.1.26