plplot 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,115 @@
1
+ --
2
+
3
+ This file includes an RDoc hack so that links can be made to open up into a new
4
+ frame rather then the current frame.
5
+
6
+ The "trick" is to append ``"target="_top'' to the URL.
7
+
8
+ ++
9
+
10
+ = Ruby/PLplot
11
+
12
+ == Introduction
13
+
14
+ This is the first public release of the Ruby bindings to
15
+ PLplot[http://plplot.sourceforge.net/"target="_top], a cross-platform software
16
+ package for creating scientific plots.
17
+
18
+ This release should be considered a beta release because the {Ruby API to
19
+ PLplot}[link:classes/PLplot.html] may change slightly based on user feedback.
20
+
21
+ == Installation
22
+
23
+ Ruby/PLplot can be installed via
24
+ RubyGems[http://www.rubygems.org/"target=_top"]:
25
+
26
+ gem install plplot
27
+
28
+ Ruby/PLplot should work with either Ruby 1.8 or 1.9. It was developed mostly
29
+ using Ruby 1.8.6 and somewhat tested against Ruby 1.9.1.
30
+
31
+ Ruby/PLplot requires a very recent version of the \PLplot libraries. Until a
32
+ new version of \PLplot is released and package maintainers support it, you will
33
+ likely have to build your own copy of the \PLplot libraries from source code
34
+ checked out from the trunk of the \PLplot source code repository. This must be
35
+ done prior to installing Ruby/PLplot. If you try to install Ruby/PLplot with
36
+ an inappropriate version of \PLplot, you will get the error message "the
37
+ \PLplot library lacks support for arbitrary storage of 2D data".
38
+
39
+ == Documentation
40
+
41
+ Documentation for the {Ruby aspects of the PLplot
42
+ API}[link:classes/PLplot.html] are installed as part of the gem-based
43
+ installation. To view the documentation, run
44
+
45
+ gem server
46
+
47
+ then point your browser to <tt>\http://localhost:8808/</tt> and navigate to
48
+ (and follow) the plplot <b>[rdoc]</b> link. You can get more information about
49
+ RubyGem's documenation server by running:
50
+
51
+ gem help server
52
+
53
+ The Ruby/PLplot API is mostly very similar to the \PLplot C API. For details
54
+ on \PLplot functionality, see the {PLplot
55
+ documentation}[http://plplot.sourceforge.net/documentation.php"target="_top].
56
+
57
+ == Examples
58
+
59
+ Ruby/PLplot provides Ruby versions of the extensive suite of \PLplot's standard
60
+ examples. The only \PLplot examples not (yet) supported are those that depend
61
+ on missing functionality (see below): x17 (stripchart), x19 (maps), and x29
62
+ (time handling).
63
+
64
+ The examples are installed automatically, but not as runnable programs. They
65
+ are "hidden" in the local gem repository. At some point they will be made more
66
+ visible, but until then you can find them in
67
+ <tt>$GEMDIR/gems/plplot-X.Y.Z/examples</tt>.
68
+
69
+ == Command line option parsing
70
+
71
+ \PLplot has many different drivers and options that can be specified by the
72
+ user. \PLplot provides excellent command line parsing functionality via its
73
+ <tt>plparseopts</tt> and related functions. Ruby also provides excellent
74
+ command line parsing via the OptionParser class. In order to provide the best
75
+ of both worlds, Ruby/PLplot provides the PLOptionParser class. This class
76
+ provides OptionParser functionality (it is a subclass of OptionParser) with
77
+ built-in support for standard \PLplot options via a modified option syntax.
78
+
79
+ Ruby/PLplot users are encouraged to use PLOptionParser for parsing command line
80
+ arguments, but it is not required. The Ruby <tt>plsetopt</tt> method is an
81
+ enhanced version of \PLplot's <tt>plsetopt</tt> function. In addition to the
82
+ "standard" calling sequence
83
+
84
+ plsetopt(opt, optarg)
85
+
86
+ <tt>plsetopt</tt> can be called with an Array of Strings (such as
87
+ <tt>ARGV</tt>) which provides functionality similar to <tt>plparseopts</tt>.
88
+ This allows for a great deal of user control over how command line arguments
89
+ are handled while still providing a simple way to leverage \PLplot's built-in
90
+ command line parsing capabilties.
91
+
92
+ == What's missing
93
+
94
+ Most of the \PLplot API is supported, but there are a few \PLplot functions
95
+ that have yet to be incorporated:
96
+
97
+ * Stripchart functions
98
+ - <tt>plstripa</tt>
99
+ - <tt>plstripc</tt>
100
+ - <tt>plstripd</tt>
101
+
102
+ * Time functions
103
+ - <tt>plbtime</tt>
104
+ - <tt>plconfigtime</tt>
105
+ - <tt>plctime</tt>
106
+
107
+ * Map functions
108
+ - <tt>plmap</tt>
109
+ - <tt>plmeridians</tt>
110
+
111
+ * Other functions
112
+ - <tt>plot3dcl</tt>
113
+ - <tt>plsmem</tt>
114
+ - <tt>plparseopts</tt> et al (but see above)
115
+ - <tt>plsurf3dl</tt>
@@ -0,0 +1,284 @@
1
+ #!/usr/bin/env ruby
2
+ $-w = true if $0 == __FILE__
3
+
4
+ require 'rubygems'
5
+ require 'plplot'
6
+ include PLplot
7
+ include NMath
8
+
9
+ # Simple line plot and multiple windows demo.
10
+ #
11
+ # Copyright (C) 2004 Rafael Laboissiere
12
+ #
13
+ # This file is part of PLplot.
14
+ #
15
+ # PLplot is free software; you can redistribute it and/or modify
16
+ # it under the terms of the GNU General Library Public License as published
17
+ # by the Free Software Foundation; either version 2 of the License, or
18
+ # (at your option) any later version.
19
+ #
20
+ # PLplot is distributed in the hope that it will be useful,
21
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ # GNU Library General Public License for more details.
24
+ #
25
+ # You should have received a copy of the GNU Library General Public License
26
+ # along with PLplot; if not, write to the Free Software
27
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28
+
29
+
30
+ # Defaults for user options. Use global variables to track user options since
31
+ # that matches the C example most closely.
32
+
33
+ $locate_mode = false
34
+ $test_xor = false
35
+ $fontset = 1
36
+ $f_name = nil
37
+
38
+ # Create PLOptionParser for parsing options
39
+
40
+ PLOP = PLOptionParser.new do |op|
41
+ op.separator('')
42
+ op.separator('x01 options:')
43
+ op.on('--locate', 'Turns on test of API locate function') do
44
+ $locate_mode = true
45
+ end
46
+ op.on('--xor', 'Turns on test of XOR') do
47
+ $test_xor = true
48
+ end
49
+ op.on('--font={0|1}', Integer, 'Selects stroke font set [1]') do |o|
50
+ raise "font must be 0 or 1" unless (0..1) === o
51
+ $font = o
52
+ end
53
+ op.on('--save=FILE', 'Save plot in color postscript file FILE') do |o|
54
+ $f_name = o
55
+ end
56
+ op.separator('')
57
+ op.separator('Make sure you get it right!')
58
+ end
59
+
60
+ def plot1(xscale, yscale, xoff, yoff, do_test)
61
+
62
+ x = NArray.float(60).indgen!(1).mul!(xscale/60.0).add!(xoff)
63
+ y = (x**2).mul!(yscale).add!(yoff)
64
+
65
+ xmin = x[0]
66
+ xmax = x[59]
67
+ ymin = y[0]
68
+ ymax = y[59]
69
+
70
+ xs=[]
71
+ ys=[]
72
+
73
+ 6.times do |i|
74
+ xs[i] = x[i * 10 + 3]
75
+ ys[i] = y[i * 10 + 3]
76
+ end
77
+
78
+ # Set up the viewport and window using PLENV. The range in X is
79
+ # 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are
80
+ # scaled separately (just = 0), and we just draw a labelled
81
+ # box (axis = 0).
82
+
83
+ plcol0(1)
84
+ plenv(xmin, xmax, ymin, ymax, 0, 0)
85
+ plcol0(2)
86
+ pllab("(x)", "(y)", "#frPLplot Example 1 - y=x#u2")
87
+
88
+ # Plot the data points
89
+
90
+ plcol0(4)
91
+ plpoin(xs, ys, 9)
92
+
93
+ # Draw the line through the data
94
+
95
+ plcol0(3)
96
+ plline(x, y)
97
+
98
+ # xor mode enable erasing a line/point/text by replotting it again
99
+ # it does not work in double buffering mode, however
100
+
101
+ if do_test && $test_xor
102
+ st = plxormod(true) # enter xor mode
103
+ if (st)
104
+ 60.times do |i|
105
+ plpoin(x[i], y[i], 9) # draw a point
106
+ sleep(0.050) # wait a little
107
+ plflush # force an update of the tk driver
108
+ plpoin(x[i], y[i], 9) # erase point
109
+ end
110
+ plxormod(0) # leave xor mode
111
+ end
112
+ end
113
+ end
114
+
115
+ # ===============================================================
116
+
117
+ def plot2
118
+
119
+ # Set up the viewport and window using PLENV. The range in X is -2.0 to
120
+ # 10.0, and the range in Y is -0.4 to 2.0. The axes are scaled separately
121
+ # (just = 0), and we draw a box with axes (axis = 1).
122
+
123
+ plcol0(1)
124
+ plenv(-2.0, 10.0, -0.4, 1.2, 0, 1)
125
+ plcol0(2)
126
+ pllab("(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function")
127
+
128
+ # Fill up the arrays
129
+
130
+ x = NArray.float(100).indgen!(-19).div!(6)
131
+ y = sin(x)/x
132
+ y[x.eq(0).where] = 1.0
133
+
134
+ # Draw the line
135
+
136
+ plcol0(3)
137
+ plwid(2)
138
+ plline(x, y)
139
+ plwid(0) # Restore default(?)
140
+ end
141
+
142
+ # ===============================================================
143
+
144
+ def plot3
145
+
146
+ space1 = 1500
147
+ mark1 = 1500
148
+
149
+ # For the final graph we wish to override the default tick intervals, and
150
+ # so do not use plenv.
151
+
152
+ pladv(0)
153
+
154
+ # Use standard viewport, and define X range from 0 to 360 degrees, Y range
155
+ # from -1.2 to 1.2.
156
+
157
+ plvsta
158
+ plwind(0.0, 360.0, -1.2, 1.2)
159
+
160
+ # Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y.
161
+
162
+ plcol0(1)
163
+ plbox("bcnst", 60.0, 2, "bcnstv", 0.2, 2)
164
+
165
+ # Superimpose a dashed line grid, with 1.5 mm marks and spaces.
166
+
167
+ plstyl(mark1, space1)
168
+ plcol0(2)
169
+ plbox("g", 30.0, 0, "g", 0.2, 0)
170
+ plstyl
171
+
172
+ plcol0(3)
173
+ pllab("Angle (degrees)", "sine", "#frPLplot Example 1 - Sine function")
174
+
175
+ x = NArray.float(101).indgen!.mul!(3.6)
176
+ y = sin(x * (PI/180))
177
+
178
+ plcol0(4)
179
+ plline(x, y)
180
+ end
181
+
182
+ #--------------------------------------------------------------------------
183
+ # main
184
+ #
185
+ # Generates several simple line plots. Demonstrates:
186
+ # - subwindow capability
187
+ # - setting up the window, drawing plot, and labelling
188
+ # - changing the color
189
+ # - automatic axis rescaling to exponential notation
190
+ # - placing the axes in the middle of the box
191
+ # - gridded coordinate axes
192
+ #--------------------------------------------------------------------------
193
+
194
+
195
+ # plplot initialization
196
+
197
+ PLOP.parse!
198
+
199
+ # Get version number, just for kicks
200
+
201
+ puts "PLplot library version: #{PL::VERSION}"
202
+
203
+ # Initialize plplot
204
+ # Divide page into 2x2 plots
205
+ # Note: calling plstar replaces separate calls to plssub and plinit
206
+
207
+ plstar(2,2)
208
+
209
+ ## Select font set as per input flag
210
+
211
+ plfontld($fontset)
212
+
213
+ # Set up the data
214
+ # Original case
215
+
216
+ xscale = 6
217
+ yscale = 1
218
+ xoff = 0
219
+ yoff = 0
220
+
221
+ # Do a plot
222
+
223
+ plot1(xscale, yscale, xoff, yoff, 0)
224
+
225
+ # Set up the data
226
+
227
+ xscale = 1
228
+ yscale = 0.0014
229
+ yoff = 0.0185
230
+
231
+ # Do a plot
232
+
233
+ digmax = 5
234
+ plsyax(digmax, 0)
235
+
236
+ plot1(xscale, yscale, xoff, yoff, 1)
237
+
238
+ plot2
239
+
240
+ plot3
241
+
242
+ # Show how to save a plot:
243
+ # Open a new device, make it current, copy parameters,
244
+ # and replay the plot buffer
245
+
246
+ if ($f_name) # command line option '-save filename'
247
+ printf("The current plot was saved in color Postscript under the name `%s'.\n", $f_name)
248
+ cur_strm = plgstrm # get current stream
249
+ new_strm = plmkstrm # create a new one
250
+
251
+ plsfnam($f_name) # file name
252
+ plsdev("psc") # device type
253
+
254
+ plcpstrm(cur_strm, 0) # copy old stream parameters to new stream
255
+ plreplot # do the save by replaying the plot buffer
256
+ plend1 # finish the device
257
+
258
+ plsstrm(cur_strm) # return to previous stream
259
+ end
260
+
261
+ # Let's get some user input
262
+
263
+ if ($locate_mode)
264
+ while(true)
265
+ break unless gin = plGetCursor
266
+ break if gin.keysym == PLK::Escape
267
+
268
+ pltext
269
+ if gin.keystr
270
+ printf("subwin = %d, wx = %f, wy = %f, dx = %f, dy = %f, c = '%s', state = 0x%08x\n",
271
+ gin.subwindow, gin.wx, gin.wy, gin.dx, gin.dy, gin.keystr, gin.state)
272
+ else
273
+ printf("subwin = %d, wx = %f, wy = %f, dx = %f, dy = %f, c = 0x%08x, state = 0x%08x\n",
274
+ gin.subwindow, gin.wx, gin.wy, gin.dx, gin.dy, gin.keysym, gin.state)
275
+ end
276
+
277
+ plgra
278
+ end
279
+ end
280
+
281
+ # Don't forget to call plend to finish off!
282
+
283
+ plend1
284
+ plend
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env ruby
2
+ $-w = true if $0 == __FILE__
3
+
4
+ require 'rubygems'
5
+ require 'plplot'
6
+ include PLplot
7
+
8
+ # Multiple window and color map 0 demo.
9
+ #
10
+ # Demonstrates multiple windows and color map 0 palette, both default and
11
+ # user-modified.
12
+
13
+ #--------------------------------------------------------------------------*\
14
+ # demo1
15
+ #
16
+ # Demonstrates multiple windows and default color map 0 palette.
17
+ #--------------------------------------------------------------------------*/
18
+
19
+ def demo1
20
+
21
+ plbop
22
+
23
+ # Divide screen into 16 regions */
24
+ plssub(4, 4)
25
+
26
+ draw_windows( 16, 0 )
27
+
28
+ pleop
29
+ end
30
+
31
+ #--------------------------------------------------------------------------*\
32
+ # demo2
33
+ #
34
+ # Demonstrates multiple windows, user-modified color map 0 palette, and
35
+ # HLS -> RGB translation.
36
+ #--------------------------------------------------------------------------*/
37
+
38
+ def demo2
39
+
40
+ # Set up cmap0 */
41
+ # Use 100 custom colors in addition to base 16 */
42
+ n = 100+16
43
+ r = NArray.int(n)
44
+ g = NArray.int(n)
45
+ b = NArray.int(n)
46
+
47
+ # Min & max lightness values */
48
+ lmin = 0.15
49
+ lmax = 0.85
50
+
51
+ plbop
52
+
53
+ # Divide screen into 100 regions
54
+
55
+ plssub(10, 10)
56
+
57
+ 100.times do |i|
58
+
59
+ # Bounds on HLS, from plhlsrgb commentary --
60
+ # hue [0., 360.] degrees
61
+ # lightness [0., 1.] magnitude
62
+ # saturation [0., 1.] magnitude
63
+
64
+ # Vary hue uniformly from left to right
65
+ h = (360.0 / 10.0 ) * ( i % 10 )
66
+ # Vary lightness uniformly from top to bottom, between min & max
67
+ l = lmin + (lmax - lmin) * (i / 10) / 9.0
68
+ # Use max saturation
69
+ s = 1.0
70
+
71
+ r1, g1, b1 = plhlsrgb(h, l, s)
72
+ #printf("%3d %15.9f %15.9f %15.9f %15.9f %15.9f %15.9f\n",
73
+ # i+16,h,l,s,r1,g1,b1)
74
+
75
+ # Use 255.001 to avoid close truncation decisions in this example. */
76
+ r[i+16] = r1 * 255.001
77
+ g[i+16] = g1 * 255.001
78
+ b[i+16] = b1 * 255.001
79
+ end
80
+
81
+ # Load default cmap0 colors into our custom set
82
+ 16.times {|i| r[i], g[i], b[i] = plgcol0(i)}
83
+
84
+ #n.times {|i| printf("%3d %3d %3d %3d\n", i, r[i], g[i], b[i])}
85
+
86
+ # Now set cmap0 all at once (faster, since fewer driver calls) */
87
+ plscmap0(r, g, b)
88
+
89
+ draw_windows( 100, 16 )
90
+
91
+ pleop
92
+ end
93
+
94
+ #--------------------------------------------------------------------------
95
+ # draw_windows
96
+ #
97
+ # Draws a set of numbered boxes with colors according to cmap0 entry.
98
+ #--------------------------------------------------------------------------
99
+
100
+ def draw_windows(nw, cmap0_offset)
101
+
102
+ plschr(0.0, 3.5)
103
+ plfont(4)
104
+
105
+ nw.times do |i|
106
+ plcol0(i+cmap0_offset)
107
+ text = i.to_s
108
+ pladv(0)
109
+ vmin = 0.1
110
+ vmax = 0.9
111
+ 3.times do |j|
112
+ plwid(j + 1)
113
+ plvpor(vmin, vmax, vmin, vmax)
114
+ plwind(0.0, 1.0, 0.0, 1.0)
115
+ plbox("bc", 0.0, 0, "bc", 0.0, 0)
116
+ vmin = vmin + 0.1
117
+ vmax = vmax - 0.1
118
+ end
119
+ plwid(1)
120
+ plptex(0.5, 0.5, 1.0, 0.0, 0.5, text)
121
+ end
122
+ end
123
+
124
+ # Parse and process command line arguments
125
+ PLOptionParser.parse!
126
+
127
+ # Initialize plplot
128
+ plinit
129
+
130
+ # Run demos
131
+ demo1
132
+ demo2
133
+
134
+ plend