plplot 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ $-w = true if $0 == __FILE__
3
+
4
+ require 'rubygems'
5
+ require 'plplot'
6
+ include PLplot
7
+
8
+ # Bar chart demo.
9
+
10
+ def plfbox( x0, y0 )
11
+ x = [x0, x0, 1+x0, 1+x0]
12
+ y = [ 0, y0, y0, 0]
13
+ plfill( x, y )
14
+ plcol0( 1 )
15
+ pllsty( 1 )
16
+ plline( x, y )
17
+ end
18
+
19
+ #--------------------------------------------------------------------------
20
+ # Does a simple bar chart, using color fill. If color fill is
21
+ # unavailable, pattern fill is used instead (automatic).
22
+ #--------------------------------------------------------------------------
23
+
24
+ # int i
25
+ # char string[20]
26
+ # PLFLT y0[10]
27
+
28
+ pos = [ 0.0, 0.25, 0.5, 0.75, 1.0 ]
29
+ red = [ 0.0, 0.25, 0.5, 1.0, 1.0 ]
30
+ green = [ 1.0, 0.5, 0.5, 0.5, 1.0 ]
31
+ blue = [ 1.0, 1.0, 0.5, 0.25, 0.0 ]
32
+
33
+ # Parse and process command line arguments
34
+
35
+ PLOptionParser.parse!
36
+
37
+ # Initialize plplot
38
+
39
+ plinit
40
+
41
+ pladv( 0 )
42
+ plvsta
43
+ plwind( 1980.0, 1990.0, 0.0, 35.0 )
44
+ plbox( "bc", 1.0, 0, "bcnv", 10.0, 0 )
45
+ plcol0( 2 )
46
+ pllab( "Year", "Widget Sales (millions)", "#frPLplot Example 12" )
47
+
48
+ y0 = [5, 15, 12, 24, 28, 30, 20, 8, 12, 3]
49
+
50
+ plscmap1l( PL::CMAP_RGB, pos, red, green, blue)
51
+
52
+ 10.times do |i|
53
+ #plcol0(i + 1)
54
+ plcol1( i / 9.0 )
55
+ plpsty( 0 )
56
+ plfbox( ( 1980.0 + i ), y0[i] )
57
+ string = "%.0f" % y0[i]
58
+ plptex( ( 1980.0 + i + 0.5 ), ( y0[i] + 1.0 ), 1.0, 0.0, 0.5, string )
59
+ string = "#{1980 + i}"
60
+ plmtex( "b", 1.0, ( ( i + 1 ) * 0.1 - 0.05 ), 0.5, string )
61
+ end
62
+
63
+ # Don't forget to call plend to finish off!
64
+
65
+ plend
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env ruby
2
+ $-w = true if $0 == __FILE__
3
+
4
+ require 'rubygems'
5
+ require 'plplot'
6
+ include PLplot
7
+ include Math
8
+
9
+ # Pie chart demo.
10
+
11
+ text = [
12
+ "Maurice",
13
+ "Geoffrey",
14
+ "Alan",
15
+ "Rafael",
16
+ "Vince"
17
+ ]
18
+
19
+ #--------------------------------------------------------------------------
20
+ # Does a simple pie chart.
21
+ #--------------------------------------------------------------------------
22
+
23
+ # int i, j, dthet, theta0, theta1, theta
24
+ # PLFLT just, dx, dy
25
+ # static PLFLT x[500], y[500], per[5]
26
+
27
+ per = [10.0, 32.0, 12.0, 30.0, 16.0]
28
+
29
+ # Parse and process command line arguments
30
+
31
+ PLOptionParser.parse!
32
+
33
+ # Initialize plplot
34
+
35
+ plinit
36
+
37
+ pladv( 0 )
38
+ # Ensure window has aspect ratio of one so circle is
39
+ # plotted as a circle.
40
+ plvasp( 1.0 )
41
+ plwind( 0.0, 10.0, 0.0, 10.0 )
42
+ # plenv(0.0, 10.0, 0.0, 10.0, 1, -2)
43
+ plcol0( 2 )
44
+ # n.b. all theta quantities scaled by 2*PI/500 to be integers to avoid
45
+ # floating point logic problems.
46
+ theta0 = 0
47
+ dthet = 1
48
+ 5.times do |i|
49
+ x = [5.0]
50
+ y = [5.0]
51
+ j = 1
52
+ # n.b. the theta quantities multiplied by 2*PI/500 afterward so
53
+ # in fact per is interpreted as a percentage.
54
+ theta1 = ( theta0 + 5 * per[i] )
55
+ if ( i == 4 )
56
+ theta1 = 500
57
+ end
58
+ theta0.step(theta1, dthet) do |theta|
59
+ x[j] = 5 + 3 * cos( ( 2.0 * PI / 500.0 ) * theta )
60
+ y[j] = 5 + 3 * sin( ( 2.0 * PI / 500.0 ) * theta )
61
+ j += 1
62
+ end
63
+ plcol0( i + 1 )
64
+ plpsty( ( i + 3 ) % 8 + 1 )
65
+ plfill( x, y )
66
+ plcol0( 1 )
67
+ plline( x, y )
68
+ just = ( 2.0 * PI / 500.0 ) * ( theta0 + theta1 ) / 2.0
69
+ dx = 0.25 * cos( just )
70
+ dy = 0.25 * sin( just )
71
+ if ( ( theta0 + theta1 ) < 250 || ( theta0 + theta1 ) > 750 )
72
+ just = 0.0
73
+ else
74
+ just = 1.0
75
+ end
76
+
77
+ plptex( ( x[j / 2] + dx ), ( y[j / 2] + dy ), 1.0, 0.0, just, text[i] )
78
+ theta0 = theta1 #- dthet
79
+ end
80
+ plfont( 2 )
81
+ plschr( 0.0, 1.3 )
82
+ plptex( 5.0, 9.0, 1.0, 0.0, 0.5, "Percentage of Sales" )
83
+
84
+ # Don't forget to call PLEND to finish off!
85
+
86
+ plend
@@ -0,0 +1,391 @@
1
+ #!/usr/bin/env ruby
2
+ $-w = true if $0 == __FILE__
3
+
4
+ require 'rubygems'
5
+ require 'plplot'
6
+ include PLplot
7
+ include Math
8
+
9
+ # Demo of multiple stream/window capability (requires Tk or Tcl-DP).
10
+ #
11
+ # Maurice LeBrun
12
+ # IFS, University of Texas at Austin
13
+ #
14
+ # Copyright (C) 2004 Alan W. Irwin
15
+ #
16
+ # This file is part of PLplot.
17
+ #
18
+ # PLplot is free software; you can redistribute it and/or modify
19
+ # it under the terms of the GNU General Library Public License as published
20
+ # by the Free Software Foundation; either version 2 of the License, or
21
+ # (at your option) any later version.
22
+ #
23
+ # PLplot is distributed in the hope that it will be useful,
24
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+ # GNU Library General Public License for more details.
27
+ #
28
+ # You should have received a copy of the GNU Library General Public License
29
+ # along with PLplot; if not, write to the Free Software
30
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31
+
32
+ #static PLFLT x[101], y[101]
33
+ #static PLFLT xscale, yscale, xoff, yoff, xs[6], ys[6]
34
+ #static PLINT space0 = 0, mark0 = 0, space1 = 1500, mark1 = 1500
35
+
36
+ # ===============================================================
37
+
38
+ # Makes transliteration from C example easier
39
+ def pow(a,b)
40
+ a ** b
41
+ end
42
+
43
+ def plot1(xscale, yscale, xoff, yoff)
44
+ x = NArray.float(60)
45
+ y = NArray.float(60)
46
+ 60.times do |i|
47
+ x[i] = xoff + xscale * (i + 1) / 60.0
48
+ y[i] = yoff + yscale * pow(x[i], 2.0)
49
+ end
50
+
51
+ xmin = x[0]
52
+ xmax = x[59]
53
+ ymin = y[0]
54
+ ymax = y[59]
55
+
56
+ xs = []
57
+ ys = []
58
+ 6.times do |i|
59
+ xs[i] = x[i * 10 + 3]
60
+ ys[i] = y[i * 10 + 3]
61
+ end
62
+
63
+ # Set up the viewport and window using PLENV. The range in X is
64
+ # 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are
65
+ # scaled separately (just = 0), and we just draw a labelled
66
+ # box (axis = 0).
67
+
68
+ plcol0(1)
69
+ plenv(xmin, xmax, ymin, ymax, 0, 0)
70
+ plcol0(6)
71
+ pllab("(x)", "(y)", "#frPLplot Example 1 - y=x#u2")
72
+
73
+ # Plot the data points
74
+
75
+ plcol0(9)
76
+ plpoin(xs, ys, 9)
77
+
78
+ # Draw the line through the data
79
+
80
+ plcol0(4)
81
+ plline(x, y)
82
+ plflush
83
+ end
84
+
85
+
86
+ # ===============================================================
87
+
88
+ def plot2
89
+ # Set up the viewport and window using PLENV. The range in X is -2.0 to
90
+ # 10.0, and the range in Y is -0.4 to 2.0. The axes are scaled separately
91
+ # (just = 0), and we draw a box with axes (axis = 1).
92
+
93
+ plcol0(1)
94
+ plenv(-2.0, 10.0, -0.4, 1.2, 0, 1)
95
+ plcol0(2)
96
+ pllab("(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function")
97
+
98
+ # Fill up the arrays
99
+
100
+ x = NArray.float(100)
101
+ y = NArray.float(100)
102
+ 100.times do |i|
103
+ x[i] = (i - 19.0) / 6.0
104
+ y[i] = 1.0
105
+ if (x[i] != 0.0)
106
+ y[i] = sin(x[i]) / x[i]
107
+ end
108
+ end
109
+
110
+ # Draw the line
111
+
112
+ plcol0(3)
113
+ plline(x, y)
114
+ plflush
115
+ end
116
+
117
+ # ===============================================================
118
+
119
+ def plot3
120
+ # For the final graph we wish to override the default tick intervals, and
121
+ # so do not use PLENV
122
+
123
+ pladv(0)
124
+
125
+ # Use standard viewport, and define X range from 0 to 360 degrees, Y range
126
+ # from -1.2 to 1.2.
127
+
128
+ plvsta
129
+ plwind(0.0, 360.0, -1.2, 1.2)
130
+
131
+ # Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y.
132
+
133
+ plcol0(1)
134
+ plbox("bcnst", 60.0, 2, "bcnstv", 0.2, 2)
135
+
136
+ # Superimpose a dashed line grid, with 1.5 mm marks and spaces. plstyl
137
+ # expects a pointer!!
138
+
139
+ plstyl(1500, 1500)
140
+ plcol0(2)
141
+ plbox("g", 30.0, 0, "g", 0.2, 0)
142
+ plstyl
143
+
144
+ plcol0(3)
145
+ pllab("Angle (degrees)", "sine", "#frPLplot Example 1 - Sine function")
146
+
147
+ x = NArray.float(101)
148
+ y = NArray.float(101)
149
+ 101.times do |i|
150
+ x[i] = 3.6 * i
151
+ y[i] = sin(x[i] * PI / 180.0)
152
+ end
153
+
154
+ plcol0(4)
155
+ plline(x, y)
156
+ plflush
157
+ end
158
+
159
+ # ===============================================================
160
+
161
+ def plot4
162
+ x0 = NArray.float(361)
163
+ y0 = NArray.float(361)
164
+ x = NArray.float(361)
165
+ y = NArray.float(361)
166
+ dtr = PI / 180.0
167
+ 361.times do |i|
168
+ x0[i] = cos(dtr * i)
169
+ y0[i] = sin(dtr * i)
170
+ end
171
+
172
+ # Set up viewport and window, but do not draw box
173
+
174
+ plenv(-1.3, 1.3, -1.3, 1.3, 1, -2)
175
+ (1..10).each do |i|
176
+ 361.times do |j|
177
+ x[j] = 0.1 * i * x0[j]
178
+ y[j] = 0.1 * i * y0[j]
179
+ end
180
+
181
+ # Draw circles for polar grid
182
+
183
+ plline(x, y)
184
+ end
185
+
186
+ plcol0(2)
187
+ 12.times do |i|
188
+ theta = 30.0 * i
189
+ dx = cos(dtr * theta)
190
+ dy = sin(dtr * theta)
191
+
192
+ # Draw radial spokes for polar grid
193
+
194
+ pljoin(0.0, 0.0, dx, dy)
195
+ text = theta.round
196
+
197
+ # Write labels for angle
198
+
199
+ # Slightly off zero to avoid floating point logic flips at 90 and 270 deg.
200
+ if (dx >= -0.00001)
201
+ plptex(dx, dy, dx, dy, -0.15, text)
202
+ else
203
+ plptex(dx, dy, -dx, -dy, 1.15, text)
204
+ end
205
+ end
206
+
207
+ # Draw the graph
208
+
209
+ 361.times do |i|
210
+ r = sin(dtr * (5 * i))
211
+ x[i] = x0[i] * r
212
+ y[i] = y0[i] * r
213
+ end
214
+ plcol0(3)
215
+ plline(x, y)
216
+
217
+ plcol0(4)
218
+ plmtex("t", 2.0, 0.5, 0.5,
219
+ "#frPLplot Example 3 - r(#gh)=sin 5#gh")
220
+ plflush
221
+ end
222
+
223
+ # ===============================================================
224
+
225
+ # Demonstration of contour plotting
226
+
227
+ XPTS = 35
228
+ YPTS = 46
229
+ XSPA = 2.0 / (XPTS - 1.0)
230
+ YSPA = 2.0 / (YPTS - 1.0)
231
+
232
+ TR = [ XSPA, 0.0, -1.0, 0.0, YSPA, -1.0 ]
233
+
234
+ def mypltr(x, y, tr)
235
+ tx = tr[0] * x.to_f + tr[1] * y.to_f + tr[2];
236
+ ty = tr[3] * x.to_f + tr[4] * y.to_f + tr[5];
237
+ [tx, ty]
238
+ end
239
+
240
+
241
+ CLEVEL = [ -1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 ]
242
+
243
+ def plot5
244
+ mark = 1500
245
+ space = 1500
246
+
247
+ # Set up function arrays
248
+
249
+ z = NArray.float(YPTS, XPTS);
250
+ w = NArray.float(YPTS, XPTS);
251
+
252
+ XPTS.times do |i|
253
+ xx = (i - (XPTS / 2.0)) / (XPTS / 2.0);
254
+ YPTS.times do |j|
255
+ yy = (j - (YPTS / 2.0)) / (YPTS / 2.0) - 1.0;
256
+ z[j,i] = xx * xx - yy * yy;
257
+ w[j,i] = 2 * xx * yy;
258
+ end
259
+ end
260
+
261
+ plenv(-1.0, 1.0, -1.0, 1.0, 0, 0)
262
+ plcol0(2)
263
+ plcont(z, nil, nil, CLEVEL) {|x,y| mypltr(x, y, TR)}
264
+ plstyl(mark, space)
265
+ plcol0(3)
266
+ plcont(w, nil, nil, CLEVEL) {|x,y| mypltr(x, y, TR)}
267
+ plcol0(1)
268
+ pllab("X Coordinate", "Y Coordinate", "Streamlines of flow")
269
+ plflush
270
+ end
271
+
272
+ #-------------------------------------------------------------------------
273
+ # Plots several simple functions from other example programs.
274
+ #
275
+ # This version sends the output of the first 4 plots (one page) to two
276
+ # independent streams.
277
+ #--------------------------------------------------------------------------
278
+
279
+ # Select either TK or DP driver and use a small window
280
+ # Using DP results in a crash at the end due to some odd cleanup problems
281
+ # The geometry strings MUST be in writable memory
282
+
283
+ geometry_master = "500x410+100+200"
284
+ geometry_slave = "500x410+650+200"
285
+
286
+ # Parse and process command line arguments
287
+
288
+ PLOptionParser.parse!
289
+
290
+ # If valid geometry specified on command line, use it for both streams.
291
+ xp0, yp0, xleng0, yleng0, xoff0, yoff0 = plgpage
292
+ valid_geometry = (xleng0 > 0 && yleng0 > 0)
293
+
294
+ # Set up first stream
295
+
296
+ if (valid_geometry)
297
+ plspage(xp0, yp0, xleng0, yleng0, xoff0, yoff0)
298
+ else
299
+ plsetopt("geometry", geometry_master)
300
+ end
301
+
302
+ plssub(2, 2)
303
+ plinit
304
+
305
+ driver = plgdev
306
+ fam, num, bmax = plgfam
307
+
308
+ printf("Demo of multiple output streams via the %s driver.\n", driver)
309
+ printf("Running with the second stream as slave to the first.\n")
310
+ printf("\n")
311
+
312
+ # Start next stream
313
+
314
+ plsstrm(1)
315
+
316
+ if (valid_geometry)
317
+ plspage(xp0, yp0, xleng0, yleng0, xoff0, yoff0)
318
+ else
319
+ plsetopt("geometry", geometry_slave)
320
+ end
321
+
322
+ # Turn off pause to make this a slave (must follow master)
323
+ plspause(0)
324
+ plsdev(driver)
325
+ plsfam(fam, num, bmax)
326
+ # Currently number of digits in format number can only be
327
+ # set via the command line option
328
+ plsetopt("fflen", "2")
329
+ plinit
330
+
331
+ # Set up the data & plot
332
+ # Original case
333
+
334
+ plsstrm(0)
335
+
336
+ xscale = 6.0
337
+ yscale = 1.0
338
+ xoff = 0.0
339
+ yoff = 0.0
340
+ plot1(xscale, yscale, xoff, yoff)
341
+
342
+ # Set up the data & plot
343
+
344
+ xscale = 1.0
345
+ yscale = 1.0e+6
346
+ plot1(xscale, yscale, xoff, yoff)
347
+
348
+ # Set up the data & plot
349
+
350
+ xscale = 1.0
351
+ yscale = 1.0e-6
352
+ digmax = 2
353
+ plsyax(digmax, 0)
354
+ plot1(xscale, yscale, xoff, yoff)
355
+
356
+ # Set up the data & plot
357
+
358
+ xscale = 1.0
359
+ yscale = 0.0014
360
+ yoff = 0.0185
361
+ digmax = 5
362
+ plsyax(digmax, 0)
363
+ plot1(xscale, yscale, xoff, yoff)
364
+
365
+ # To slave
366
+ # The pleop ensures the eop indicator gets lit.
367
+
368
+ plsstrm(1)
369
+ plot4
370
+ pleop
371
+
372
+ # Back to master
373
+
374
+ plsstrm(0)
375
+ plot2
376
+ plot3
377
+
378
+ # To slave
379
+
380
+ plsstrm(1)
381
+ plot5
382
+ pleop
383
+
384
+ # Back to master to wait for user to advance
385
+
386
+ plsstrm(0)
387
+ pleop
388
+
389
+ # Call plend to finish off.
390
+
391
+ plend