plplot 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,266 @@
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
+ # Shade plot demo.
10
+ #
11
+ # Maurice LeBrun
12
+ # IFS, University of Texas at Austin
13
+ # 31 Aug 1993
14
+
15
+ XPTS = 35 # Data points in x
16
+ YPTS = 46 # Data points in y
17
+
18
+
19
+ #--------------------------------------------------------------------------
20
+ # cmap1_init1
21
+ #
22
+ # Initializes color map 1 in HLS space.
23
+ #--------------------------------------------------------------------------
24
+
25
+ def cmap1_init1
26
+ i = [
27
+ 0, # left boundary
28
+ 0.45, # just before center
29
+ 0.55, # just after center
30
+ 1 # right boundary
31
+ ]
32
+
33
+ h = [
34
+ 260, # hue -- low: blue-violet
35
+ 260, # only change as we go over vertex
36
+ 20, # hue -- high: red
37
+ 20 # keep fixed
38
+ ]
39
+
40
+ l = [
41
+ 0.5, # lightness -- low
42
+ 0.0, # lightness -- center
43
+ 0.0, # lightness -- center
44
+ 0.5 # lightness -- high
45
+ ]
46
+
47
+ s = [
48
+ 1, # maximum saturation
49
+ 1, # maximum saturation
50
+ 1, # maximum saturation
51
+ 1 # maximum saturation
52
+ ]
53
+
54
+ plscmap1l( 0, i, h, l, s )
55
+ end
56
+
57
+ #--------------------------------------------------------------------------\
58
+ # cmap1_init2
59
+ #
60
+ # Initializes color map 1 in HLS space.
61
+ #--------------------------------------------------------------------------/
62
+
63
+ def cmap1_init2
64
+ i = [
65
+ 0, # left boundary
66
+ 0.45, # just before center
67
+ 0.55, # just after center
68
+ 1 # right boundary
69
+ ]
70
+
71
+ h = [
72
+ 260, # hue -- low: blue-violet
73
+ 260, # only change as we go over vertex
74
+ 20, # hue -- high: red
75
+ 20 # keep fixed
76
+ ]
77
+
78
+ l = [
79
+ 0.6, # lightness -- low
80
+ 0.0, # lightness -- center
81
+ 0.0, # lightness -- center
82
+ 0.6 # lightness -- high
83
+ ]
84
+
85
+ s = [
86
+ 1, # saturation -- low
87
+ 0.5, # saturation -- center
88
+ 0.5, # saturation -- center
89
+ 1 # saturation -- high
90
+ ]
91
+
92
+ plscmap1l( 0, i, h, l, s )
93
+ end
94
+
95
+ #--------------------------------------------------------------------------\
96
+ # plot1
97
+ #
98
+ # Illustrates a single shaded region.
99
+ #--------------------------------------------------------------------------/
100
+
101
+ def plot1(z)
102
+
103
+ zmin, zmax = plMinMax2dGrid(z)
104
+
105
+ pladv( 0 )
106
+ plvpor( 0.1, 0.9, 0.1, 0.9 )
107
+ plwind( -1.0, 1.0, -1.0, 1.0 )
108
+
109
+ # Plot using identity transform
110
+
111
+ shade_min = zmin + ( zmax - zmin ) * 0.4
112
+ shade_max = zmin + ( zmax - zmin ) * 0.6
113
+ sh_cmap = 0
114
+ sh_color = 7
115
+ sh_width = 2
116
+ min_color = 9
117
+ max_color = 2
118
+ min_width = 2
119
+ max_width = 2
120
+
121
+ plpsty( 8 )
122
+ plshade(z, -1..1, -1..1,
123
+ shade_min..shade_max,
124
+ sh_color, sh_width,
125
+ min_color..max_color,
126
+ min_width..max_width,
127
+ 1)
128
+
129
+ plcol0( 1 )
130
+ plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 )
131
+ plcol0( 2 )
132
+ pllab( "distance", "altitude", "Bogon flux" )
133
+ end
134
+
135
+ #--------------------------------------------------------------------------
136
+ # plot2
137
+ #
138
+ # Illustrates multiple adjacent shaded regions, using different fill
139
+ # patterns for each region.
140
+ #--------------------------------------------------------------------------
141
+
142
+ def plot2(z)
143
+
144
+ inc = [
145
+ [ 450 ], [ -450 ], [ 0 ], [ 900 ],
146
+ [ 300 ], [ 450, -450 ], [ 0, 900 ], [ 0, 450 ],
147
+ [ 450, -450 ], [ 0, 900 ]
148
+ ]
149
+
150
+ del = [
151
+ [ 2000 ], [ 2000 ], [ 2000 ],
152
+ [ 2000 ], [ 2000 ], [ 2000, 2000 ],
153
+ [ 2000, 2000 ], [ 2000, 2000 ], [ 4000, 4000 ],
154
+ [ 4000, 2000 ]
155
+ ]
156
+
157
+ sh_width = 2
158
+
159
+ pladv( 0 )
160
+ plvpor( 0.1, 0.9, 0.1, 0.9 )
161
+ plwind( -1.0, 1.0, -1.0, 1.0 )
162
+
163
+ # Plot using identity transform
164
+
165
+ zmin, zmax = plMinMax2dGrid(z)
166
+
167
+ 10.times do |i|
168
+ shade_min = zmin + ( zmax - zmin ) * i / 10.0
169
+ shade_max = zmin + ( zmax - zmin ) * ( i + 1 ) / 10.0
170
+ sh_color = i + 6
171
+ plpat( inc[i], del[i] )
172
+
173
+ plshade(z, -1..1, -1..1,
174
+ shade_min..shade_max,
175
+ sh_color, sh_width,
176
+ nil, nil,
177
+ 1)
178
+ end
179
+
180
+ plcol0( 1 )
181
+ plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 )
182
+ plcol0( 2 )
183
+ pllab( "distance", "altitude", "Bogon flux" )
184
+ end
185
+
186
+ #--------------------------------------------------------------------------
187
+ # plot3
188
+ #
189
+ # Illustrates shaded regions in 3d, using a different fill pattern for
190
+ # each region.
191
+ #--------------------------------------------------------------------------
192
+
193
+ def plot3
194
+ xx = [
195
+ [ -1.0, 1.0, 1.0, -1.0, -1.0 ],
196
+ [ -1.0, 1.0, 1.0, -1.0, -1.0 ]
197
+ ]
198
+ yy = [
199
+ [ 1.0, 1.0, 0.0, 0.0, 1.0 ],
200
+ [ -1.0, -1.0, 0.0, 0.0, -1.0 ]
201
+ ]
202
+ zz = [
203
+ [ 0.0, 0.0, 1.0, 1.0, 0.0 ],
204
+ [ 0.0, 0.0, 1.0, 1.0, 0.0 ]
205
+ ]
206
+
207
+ pladv( 0 )
208
+ plvpor( 0.1, 0.9, 0.1, 0.9 )
209
+ plwind( -1.0, 1.0, -1.0, 1.0 )
210
+ plw3d( 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 0.0, 1.5, 30, -40 )
211
+
212
+ # Plot using identity transform
213
+
214
+ plcol0( 1 )
215
+ plbox3( "bntu", "X", 0.0, 0, "bntu", "Y", 0.0, 0, "bcdfntu", "Z", 0.5, 0 )
216
+ plcol0( 2 )
217
+ pllab( "", "", "3-d polygon filling" )
218
+
219
+ plcol0( 3 )
220
+ plpsty( 1 )
221
+ plline3( xx[0], yy[0], zz[0] )
222
+ plfill3( xx[0][0,4], yy[0][0,4], zz[0][0,4] )
223
+ plpsty( 2 )
224
+ plline3( xx[1], yy[1], zz[1] )
225
+ plfill3( xx[1][0,4], yy[1][0,4], zz[1][0,4] )
226
+ end
227
+
228
+ #--------------------------------------------------------------------------
229
+ # Does a variety of shade plots.
230
+ #--------------------------------------------------------------------------
231
+
232
+
233
+ # Parse and process command line arguments
234
+
235
+ PLOptionParser.parse!
236
+
237
+ # Set up color map 0
238
+
239
+ #plscmap0n(3)
240
+
241
+ # Set up color map 1
242
+
243
+ cmap1_init2
244
+
245
+ # Initialize plplot
246
+
247
+ plinit
248
+
249
+ # Set up data array
250
+
251
+ z = NArray.float(YPTS, XPTS)
252
+
253
+ XPTS.times do |i|
254
+ xx = ( i - ( XPTS.to_f / 2 ) ) / ( XPTS.to_f / 2 )
255
+ YPTS.times do |j|
256
+ yy = ( j - ( YPTS.to_f / 2 ) ) / ( YPTS.to_f / 2 ) - 1.0
257
+
258
+ z[j,i] = xx * xx - yy * yy + ( xx - yy ) / ( xx * xx + yy * yy + 0.1 )
259
+ end
260
+ end
261
+
262
+ plot1(z)
263
+ plot2(z)
264
+ plot3
265
+
266
+ plend
@@ -0,0 +1,349 @@
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
+ # plshade demo, using color fill.
10
+ #
11
+ # Maurice LeBrun
12
+ # IFS, University of Texas at Austin
13
+ # 20 Mar 1994
14
+
15
+ # Fundamental settings.
16
+ #
17
+ # To get smoother color variation, increase ns, nx, and ny. To get faster
18
+ # response (especially on a serial link), decrease them. A decent but quick
19
+ # test results from ns around 5 and nx, ny around 25.
20
+
21
+ # Defaults for user options. Use global variables to track user options since
22
+ # that matches the C example most closely.
23
+
24
+ $ns = 20 # Default number of shade levels
25
+ $nx = 35 # Default number of data points in x
26
+ $ny = 46 # Default number of data points in y
27
+ $exclude = false # By default do not plot a page illustrating
28
+ # exclusion. API is probably going to change
29
+ # anyway, but can only be reproduced by
30
+ # the C and Ruby (and ocaml?) front ends
31
+
32
+ # polar plot data
33
+ PERIMETERPTS = 100
34
+
35
+ # Transformation function (modified below)
36
+
37
+ TR = [
38
+ 1.0, 0.0, -1.0,
39
+ 0.0, 1.0, -1.0
40
+ ]
41
+
42
+ def mypltr(x, y, tr)
43
+ tx = tr[0] * x.to_f + tr[1] * y.to_f + tr[2]
44
+ ty = tr[3] * x.to_f + tr[4] * y.to_f + tr[5]
45
+ [tx, ty]
46
+ end
47
+
48
+ PLOP = PLOptionParser.new do |op|
49
+ op.separator('')
50
+ op.separator('x16 options:')
51
+ op.on('--exclude', "Plot the \"exclusion\" page [#{$exclude}]") do
52
+ $exclude = true
53
+ end
54
+ op.on('--ns LEVELS', Integer, "Sets number of shade levels [#{$ns}]") do |o|
55
+ $ns = o
56
+ end
57
+ op.on('--nx XPTS', Integer, "Sets number of data points in x [#{$nx}]") do |o|
58
+ $nx = o
59
+ end
60
+ op.on('--ny YPTS', Integer, "Sets number of data points in y [#{$ny}]") do |o|
61
+ $nx = o
62
+ end
63
+ op.separator('')
64
+ op.separator('To get smoother color variation, increase ns, nx, and ny. To get faster')
65
+ op.separator('response (especially on a serial link), decrease them. A decent but quick')
66
+ op.separator('test results from ns around 5 and nx, ny around 25.')
67
+ end
68
+
69
+ zdefined = lambda do |x, y|
70
+ z = sqrt(x * x + y * y)
71
+ z < 0.4 || z > 0.6
72
+ end
73
+
74
+ #--------------------------------------------------------------------------
75
+ # Does several shade plots using different coordinate mappings.
76
+ #--------------------------------------------------------------------------
77
+
78
+ fill_width = 2
79
+ cont_color = 0
80
+ cont_width = 0
81
+
82
+ # Parse and process command line arguments
83
+
84
+ PLOP.parse!
85
+
86
+ # Load colour palettes
87
+
88
+ plspal0("cmap0_black_on_white.pal")
89
+ plspal1("cmap1_gray.pal", 1)
90
+
91
+ # Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
92
+
93
+ plscmap0n(3)
94
+
95
+ # Initialize plplot
96
+
97
+ plinit
98
+
99
+ # Allocate data structures
100
+
101
+ TR[0] = 2.0 / ($nx - 1)
102
+ TR[4] = 2.0 / ($ny - 1)
103
+
104
+ clevel = NArray.float($ns)
105
+ shedge = NArray.float($ns+1)
106
+ xg1 = NArray.float($nx)
107
+ yg1 = NArray.float($ny)
108
+
109
+ xg2 = NArray.float($ny, $nx)
110
+ yg2 = NArray.float($ny, $nx)
111
+
112
+ z = NArray.float($ny, $nx)
113
+ w = NArray.float($ny, $nx)
114
+
115
+ px = NArray.float(PERIMETERPTS)
116
+ py = NArray.float(PERIMETERPTS)
117
+
118
+ # Set up data array
119
+
120
+ $nx.times do |i|
121
+ x = (i - ($nx / 2.0)) / ($nx / 2.0)
122
+
123
+ $ny.times do |j|
124
+ y = (j - ($ny / 2.0)) / ($ny / 2.0) - 1
125
+
126
+ z[j,i] = -sin(7.0 * x) * cos(7.0 * y) + x * x - y * y
127
+ w[j,i] = -cos(7.0 * x) * sin(7.0 * y) + 2 * x * y
128
+ end
129
+ end
130
+
131
+ zmin, zmax = plMinMax2dGrid(z)
132
+
133
+ $ns.times do |i|
134
+ clevel[i] = zmin + (zmax - zmin) * (i + 0.5) / $ns
135
+ end
136
+
137
+ ($ns+1).times do |i|
138
+ shedge[i] = zmin + (zmax - zmin) * i / $ns
139
+ end
140
+
141
+ # Set up coordinate grids
142
+
143
+ $nx.times do |i|
144
+ $ny.times do |j|
145
+ x, y = mypltr(i, j, TR)
146
+
147
+ argx = x * PI / 2
148
+ argy = y * PI / 2
149
+ distort = 0.4
150
+
151
+ xg1[i] = x + distort * cos(argx)
152
+ yg1[j] = y - distort * cos(argy)
153
+
154
+ xg2[j,i] = x + distort * cos(argx) * cos(argy)
155
+ yg2[j,i] = y - distort * cos(argx) * cos(argy)
156
+ end
157
+ end
158
+
159
+ # Plot using identity transform
160
+
161
+ pladv(0)
162
+ plvpor(0.1, 0.9, 0.1, 0.9)
163
+ plwind(-1.0, 1.0, -1.0, 1.0)
164
+
165
+ plpsty(0)
166
+
167
+ plshade(z, -1..1, -1..1,
168
+ shedge, fill_width,
169
+ cont_color, cont_width,
170
+ 1)
171
+
172
+ plcol0(1)
173
+ plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0)
174
+ plcol0(2)
175
+ #plcont(w, nil, nil, clevel) {|x,y| mypltr(x,y,TR)}
176
+
177
+ pllab("distance", "altitude", "Bogon density")
178
+
179
+ # Plot using 1d coordinate transform
180
+
181
+ # Load colour palettes
182
+ plspal0("cmap0_black_on_white.pal")
183
+ plspal1("cmap1_blue_yellow.pal", 1)
184
+ # Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
185
+ plscmap0n(3)
186
+
187
+ pladv(0)
188
+ plvpor(0.1, 0.9, 0.1, 0.9)
189
+ plwind(-1.0, 1.0, -1.0, 1.0)
190
+
191
+ plpsty(0)
192
+
193
+ plshade(z, -1..1, -1..1,
194
+ shedge, fill_width,
195
+ cont_color, cont_width,
196
+ 1, xg1, yg1)
197
+
198
+ plcol0(1)
199
+ plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0)
200
+ plcol0(2)
201
+
202
+ #plcont(w, nil, nil, clevel, xg1, xg2)
203
+
204
+ pllab("distance", "altitude", "Bogon density")
205
+
206
+ # Plot using 2d coordinate transform
207
+
208
+ # Load colour palettes
209
+ plspal0("cmap0_black_on_white.pal")
210
+ plspal1("cmap1_blue_red.pal", 1)
211
+ # Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
212
+ plscmap0n(3)
213
+
214
+ pladv(0)
215
+ plvpor(0.1, 0.9, 0.1, 0.9)
216
+ plwind(-1.0, 1.0, -1.0, 1.0)
217
+
218
+ plpsty(0)
219
+
220
+ plshade(z, -1..1, -1..1,
221
+ shedge, fill_width,
222
+ cont_color, cont_width,
223
+ 0, xg2, yg2)
224
+
225
+ plcol0(1)
226
+ plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0)
227
+ plcol0(2)
228
+ plcont(w, nil, nil, clevel, xg2, yg2)
229
+
230
+ pllab("distance", "altitude", "Bogon density, with streamlines")
231
+
232
+ # Plot using 2d coordinate transform
233
+
234
+ # Load colour palettes
235
+ plspal0(nil)
236
+ plspal1(nil, 1)
237
+ # Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
238
+ plscmap0n(3)
239
+
240
+ pladv(0)
241
+ plvpor(0.1, 0.9, 0.1, 0.9)
242
+ plwind(-1.0, 1.0, -1.0, 1.0)
243
+
244
+ plpsty(0)
245
+
246
+ plshade(z, -1..1, -1..1,
247
+ shedge, fill_width,
248
+ 2, 3,
249
+ 0, xg2, yg2)
250
+
251
+ plcol0(1)
252
+ plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0)
253
+ plcol0(2)
254
+ #plcont(w, nil, nil, clevel, xg2, yg2)
255
+
256
+ pllab("distance", "altitude", "Bogon density")
257
+
258
+ # Note this exclusion API will probably change.
259
+
260
+ # Plot using 2d coordinate transform and exclusion
261
+
262
+ if $exclude
263
+ # Load colour palettes
264
+ plspal0("cmap0_black_on_white.pal")
265
+ plspal1("cmap1_gray.pal", 1)
266
+ # Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
267
+ plscmap0n(3)
268
+
269
+ pladv(0)
270
+ plvpor(0.1, 0.9, 0.1, 0.9)
271
+ plwind(-1.0, 1.0, -1.0, 1.0)
272
+
273
+ plpsty(0)
274
+
275
+ pldefined(zdefined)
276
+
277
+ plshade(z, -1..1, -1..1,
278
+ shedge, fill_width,
279
+ cont_color, cont_width,
280
+ 0, xg2, yg2)
281
+
282
+ pldefined(nil)
283
+
284
+ plcol0(1)
285
+ plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0)
286
+
287
+ pllab("distance", "altitude", "Bogon density with exclusion")
288
+ end
289
+
290
+ # Example with polar coordinates.
291
+
292
+ # Load colour palettes
293
+ plspal0("cmap0_black_on_white.pal")
294
+ plspal1("cmap1_gray.pal", 1)
295
+ # Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
296
+ plscmap0n(3)
297
+
298
+ pladv(0)
299
+ plvpor(0.1, 0.9, 0.1, 0.9)
300
+ plwind(-1, 1, -1, 1)
301
+
302
+
303
+ plpsty(0)
304
+
305
+ # Build new coordinate matrices.
306
+
307
+ $nx.times do |i|
308
+ r = i.to_f / ($nx - 1)
309
+ $ny.times do |j|
310
+ t = 2 * PI / ($ny - 1) * j
311
+ xg2[j,i] = r * cos(t)
312
+ yg2[j,i] = r * sin(t)
313
+ z[j,i] = exp(-r * r) * cos(5 * PI * r) * cos(5 * t)
314
+ end
315
+ end
316
+
317
+ # Need a new shedge to go along with the new data set.
318
+
319
+ zmin, zmax = plMinMax2dGrid(z)
320
+
321
+ ($ns+1).times do |i|
322
+ shedge[i] = zmin + (zmax - zmin) * i / $ns
323
+ end
324
+
325
+ # Now we can shade the interior region.
326
+
327
+ plshade(z, -1..1, -1..1,
328
+ shedge, fill_width,
329
+ cont_color, cont_width,
330
+ 0, xg2, yg2)
331
+
332
+ # Now we can draw the perimeter. (If do before, shade stuff may overlap.)
333
+
334
+ PERIMETERPTS.times do |i|
335
+ t = 2 * PI / (PERIMETERPTS - 1) * i
336
+ px[i] = cos(t)
337
+ py[i] = sin(t)
338
+ end
339
+ plcol0(1)
340
+ plline(px, py)
341
+
342
+ # And label the plot.
343
+
344
+ plcol0(2)
345
+ pllab("", "", "Tokamak Bogon Instability")
346
+
347
+ # Clean up
348
+
349
+ plend