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,81 @@
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
+ # Polar plot demo.
10
+ #
11
+ # Generates polar plot, with 1-1 scaling.
12
+
13
+ n = 361
14
+
15
+ dtr = PI / 180.0
16
+ x0 = cos(NArray.float(n).indgen!.mul!(dtr))
17
+ y0 = sin(NArray.float(n).indgen!.mul!(dtr))
18
+ r = sin(NArray.float(n).indgen!.mul!(5*dtr))
19
+
20
+ # Parse and process command line arguments
21
+
22
+ PLOptionParser.parse!
23
+
24
+ # Set orientation to landscape - note not all device drivers
25
+ # support this, in particular most interactive drivers do not
26
+ plsori(1)
27
+
28
+ # Initialize plplot
29
+
30
+ plinit
31
+
32
+ # Set up viewport and window, but do not draw box
33
+
34
+ plenv(-1.3, 1.3, -1.3, 1.3, 1, -2)
35
+
36
+ # Draw circles for polar grid
37
+ #
38
+ 1.upto(10) {|i| plarc(0.0, 0.0, 0.1 * i, 0.1 * i, 0.0, 360.0, 0)}
39
+
40
+ plcol0(2)
41
+ 12.times do |i|
42
+ theta = 30.0 * i
43
+ dx = cos(dtr * theta)
44
+ dy = sin(dtr * theta)
45
+
46
+ # Draw radial spokes for polar grid
47
+
48
+ pljoin(0.0, 0.0, dx, dy)
49
+ text = theta.round.to_s
50
+
51
+ # Write labels for angle
52
+
53
+ if (theta < 9.99)
54
+ offset = 0.45
55
+ elsif (theta < 99.9)
56
+ offset = 0.30
57
+ else
58
+ offset = 0.15
59
+ end
60
+
61
+ # Slightly off zero to avoid floating point logic flips at 90 and 270 deg.
62
+ if (dx >= -0.00001)
63
+ plptex(dx, dy, dx, dy, -offset, text)
64
+ else
65
+ plptex(dx, dy, -dx, -dy, offset+1, text)
66
+ end
67
+ end
68
+
69
+ # Draw the graph
70
+
71
+ x = r * x0
72
+ y = r * y0
73
+ plcol0(3)
74
+ plline(x, y)
75
+
76
+ plcol0(4)
77
+ plmtex("t", 2.0, 0.5, 0.5, "#frPLplot Example 3 - r(#gh)=sin 5#gh")
78
+
79
+ # Close the plot at end
80
+
81
+ plend
@@ -0,0 +1,98 @@
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
+ # Log plot demo.
10
+ #
11
+ # Illustration of logarithmic axes, and redefinition of window.
12
+
13
+ # Makes transliteration from C example easier
14
+ def pow(a,b)
15
+ a ** b
16
+ end
17
+
18
+ #--------------------------------------------------------------------------*\
19
+ # plot1
20
+ #
21
+ # Log-linear plot.
22
+ #--------------------------------------------------------------------------*/
23
+
24
+ def plot1(type)
25
+
26
+ n = 101
27
+ freql = NArray.float(n)
28
+ ampl = NArray.float(n)
29
+ phase = NArray.float(n)
30
+
31
+ pladv(0)
32
+
33
+ # Set up data for log plot
34
+
35
+ f0 = 1.0
36
+ n.times do |i|
37
+ freql[i] = -2.0 + i / 20.0
38
+ freq = pow(10.0, freql[i])
39
+ ampl[i] = 20.0 * log10(1.0 / sqrt(1.0 + pow((freq / f0), 2.0)))
40
+ phase[i] = -(180.0 / PI) * atan(freq / f0)
41
+ end
42
+
43
+ plvpor(0.15, 0.85, 0.1, 0.9)
44
+ plwind(-2.0, 3.0, -80.0, 0.0)
45
+
46
+ # Try different axis and labelling styles.
47
+
48
+ plcol0(1)
49
+ case (type)
50
+ when 0
51
+ plbox("bclnst", 0.0, 0, "bnstv", 0.0, 0)
52
+ when 1
53
+ plbox("bcfghlnst", 0.0, 0, "bcghnstv", 0.0, 0)
54
+ end
55
+
56
+ # Plot ampl vs freq
57
+
58
+ plcol0(2)
59
+ plline(freql, ampl)
60
+ plcol0(1)
61
+ plptex(1.6, -30.0, 1.0, -20.0, 0.5, "-20 dB/decade")
62
+
63
+ # Put labels on
64
+
65
+ plcol0(1)
66
+ plmtex("b", 3.2, 0.5, 0.5, "Frequency")
67
+ plmtex("t", 2.0, 0.5, 0.5, "Single Pole Low-Pass Filter")
68
+ plcol0(2)
69
+ plmtex("l", 5.0, 0.5, 0.5, "Amplitude (dB)")
70
+
71
+ # For the gridless case, put phase vs freq on same plot
72
+
73
+ if (type == 0)
74
+ plcol0(1)
75
+ plwind(-2.0, 3.0, -100.0, 0.0)
76
+ plbox("", 0.0, 0, "cmstv", 30.0, 3)
77
+ plcol0(3)
78
+ plline(freql, phase)
79
+ plcol0(3)
80
+ plmtex("r", 5.0, 0.5, 0.5, "Phase shift (degrees)")
81
+ end
82
+ end
83
+
84
+ # Parse and process command line arguments
85
+
86
+ PLOptionParser.parse!
87
+
88
+ # Initialize plplot
89
+
90
+ plinit
91
+ plfont(2)
92
+
93
+ # Make log plots using two different styles.
94
+
95
+ plot1(0)
96
+ plot1(1)
97
+
98
+ plend
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ $-w = true if $0 == __FILE__
3
+
4
+ require 'plplot'
5
+ include PLplot
6
+ include NMath
7
+
8
+ # Histogram demo.
9
+ #
10
+ # Draws a histogram from sample data.
11
+
12
+ NPTS = 2047
13
+
14
+ # Parse and process command line arguments
15
+
16
+ PLOptionParser.parse!
17
+
18
+ # Initialize plplot
19
+
20
+ plinit
21
+
22
+ # Fill up data points
23
+
24
+ delta = 2.0 * PI / NPTS
25
+ data = sin(NArray.float(NPTS).indgen!.mul!(delta))
26
+
27
+ plcol0(1)
28
+ plhist(data, 44, -1.1 .. 1.1)
29
+ plcol0(2)
30
+ pllab("#frValue", "#frFrequency",
31
+ "#frPLplot Example 5 - Probability function of Oscillator")
32
+
33
+ plend
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+ $-w = true if $0 == __FILE__
3
+
4
+ require 'rubygems'
5
+ require 'plplot'
6
+ include PLplot
7
+
8
+ # --------------------------------------------------------------------------
9
+ # Font demo.
10
+ #
11
+ # Displays the entire "plpoin" symbol (font) set.
12
+ # --------------------------------------------------------------------------
13
+
14
+ # Parse and process command line arguments
15
+
16
+ PLOptionParser.parse!
17
+
18
+ # Initialize plplot
19
+
20
+ plinit
21
+
22
+ pladv(0)
23
+
24
+ # Set up viewport and window
25
+
26
+ plcol0(2)
27
+ plvpor(0.1, 1.0, 0.1, 0.9)
28
+ plwind(0.0, 1.0, 0.0, 1.3)
29
+
30
+ # Draw the grid using plbox
31
+
32
+ plbox("bcg", 0.1, 0, "bcg", 0.1, 0)
33
+
34
+ # Write the digits below the frame
35
+
36
+ plcol0(15)
37
+ 10.times do |i|
38
+ plmtex("b", 1.5, (0.1 * i + 0.05), 0.5, i)
39
+ end
40
+
41
+ k = 0
42
+ 13.times do |i|
43
+
44
+ # Write the digits to the left of the frame
45
+
46
+ plmtex("lv", 1.0, (1.0 - (2 * i + 1) / 26.0), 1.0, 10*i)
47
+
48
+ 10.times do |j|
49
+ x = 0.1 * j + 0.05
50
+ y = 1.25 - 0.1 * i
51
+
52
+ # Display the symbols (plpoin accepts scalars as well as NArrays
53
+
54
+ if (k < 128)
55
+ plpoin(x, y, k)
56
+ end
57
+ k = k + 1
58
+ end
59
+ end
60
+
61
+ plmtex("t", 1.5, 0.5, 0.5, "PLplot Example 6 - plpoin symbols")
62
+ plend
@@ -0,0 +1,69 @@
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
+ # --------------------------------------------------------------------------*\
10
+ # Font demo.
11
+ #
12
+ # Displays the entire "plsym" symbol (font) set.
13
+ # --------------------------------------------------------------------------*/
14
+
15
+ base = [
16
+ 0, 200, 500, 600, 700, 800, 900,
17
+ 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900
18
+ ]
19
+
20
+ # Parse and process command line arguments
21
+
22
+ PLOptionParser.parse!
23
+
24
+ # Initialize plplot
25
+
26
+ plinit
27
+
28
+ plfontld(1)
29
+
30
+ 17.times do |l|
31
+ pladv(0)
32
+
33
+ # Set up viewport and window
34
+
35
+ plcol0(2)
36
+ plvpor(0.15, 0.95, 0.1, 0.9)
37
+ plwind(0.0, 1.0, 0.0, 1.0)
38
+
39
+ # Draw the grid using plbox
40
+
41
+ plbox("bcg", 0.1, 0, "bcg", 0.1, 0)
42
+
43
+ # Write the digits below the frame
44
+
45
+ plcol0(15)
46
+ 10.times do |i|
47
+ plmtex("b", 1.5, (0.1 * i + 0.05), 0.5, i)
48
+ end
49
+
50
+ k = 0
51
+ 10.times do |i|
52
+
53
+ # Write the digits to the left of the frame
54
+
55
+ plmtex("lv", 1.0, (0.95 - 0.1 * i), 1.0, base[l] + 10 * i)
56
+ 10.times do |j|
57
+ x = 0.1 * j + 0.05
58
+ y = 0.95 - 0.1 * i
59
+
60
+ # Display the symbols
61
+
62
+ plsym(x, y, base[l] + k)
63
+ k = k + 1
64
+ end
65
+ end
66
+
67
+ plmtex("t", 1.5, 0.5, 0.5, "PLplot Example 7 - PLSYM symbols")
68
+ end
69
+ plend
@@ -0,0 +1,179 @@
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
+ # 3-d plot demo.
10
+ #
11
+ # Copyright (C) 2004 Alan W. Irwin
12
+ # Copyright (C) 2004 Rafael Laboissiere
13
+ #
14
+ # This file is part of PLplot.
15
+ #
16
+ # PLplot is free software; you can redistribute it and/or modify
17
+ # it under the terms of the GNU General Library Public License as published
18
+ # by the Free Software Foundation; either version 2 of the License, or
19
+ # (at your option) any later version.
20
+ #
21
+ # PLplot is distributed in the hope that it will be useful,
22
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ # GNU Library General Public License for more details.
25
+ #
26
+ # You should have received a copy of the GNU Library General Public License
27
+ # along with PLplot; if not, write to the Free Software
28
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29
+
30
+ XPTS = 35 # Data points in x
31
+ YPTS = 46 # Data points in y
32
+
33
+ alt = [60.0, 20.0]
34
+ az = [30.0, 60.0]
35
+
36
+ title = [
37
+ "#frPLplot Example 8 - Alt=60, Az=30",
38
+ "#frPLplot Example 8 - Alt=20, Az=60",
39
+ ]
40
+
41
+ # Makes transliteration from C example easier
42
+ def pow(a,b)
43
+ a ** b
44
+ end
45
+
46
+ #--------------------------------------------------------------------------
47
+ # cmap1_init1
48
+ #
49
+ # Initializes color map 1 in HLS space.
50
+ # Basic grayscale variation from half-dark (which makes more interesting
51
+ # looking plot compared to dark) to light.
52
+ # An interesting variation on this:
53
+ # s[1] = 1.0
54
+ #--------------------------------------------------------------------------
55
+
56
+ def cmap1_init(gray)
57
+
58
+ i = [0.0, 1.0]; # [left, right] boundaries
59
+
60
+ if (gray==1)
61
+ h = [0.0, 0.0] # hue -- low: red (arbitrary if s=0)
62
+ l = [0.5, 1.0] # lightness -- low: half-dark
63
+ s = [0.0, 0.0] # minimum saturation
64
+ else
65
+ h = [240, 0] # blue -> green -> yellow -> red
66
+ l = [0.6, 0.6]
67
+ s = [0.8, 0.8]
68
+ end
69
+
70
+ plscmap1n(256)
71
+ plscmap1l(PL::CMAP_HLS, i, h, l, s)
72
+ end
73
+
74
+ # Use PLOptionParser to parse options. Use global variables to track user
75
+ # options since that matches the C example most closely.
76
+
77
+ # Defaults for user options
78
+ $sombrero = false
79
+
80
+ PLOP = PLOptionParser.new do |op|
81
+ op.separator('')
82
+ op.separator('x08 options:')
83
+ op.on('--sombrero', 'Use the "sombrero" function') do
84
+ $sombrero = true
85
+ end
86
+ end
87
+
88
+ LEVELS = 10
89
+
90
+ #--------------------------------------------------------------------------
91
+ # main
92
+ #
93
+ # Does a series of 3-d plots for a given data set, with different
94
+ # viewing options in each plot.
95
+ #--------------------------------------------------------------------------
96
+
97
+ PLOP.parse!
98
+ rosen = !$sombrero
99
+
100
+ plinit
101
+
102
+ # Allocate data structures
103
+
104
+ x = NArray.float(XPTS).indgen!.div!(XPTS/2.0).sbt!(1)
105
+ y = NArray.float(YPTS).indgen!.div!(YPTS/2.0).sbt!(1)
106
+ z = NArray.float(YPTS, XPTS)
107
+
108
+ if(rosen)
109
+ x.mul!(1.5)
110
+ y.add!(0.5)
111
+ end
112
+
113
+ XPTS.times do |i|
114
+ xx = x[i]
115
+ YPTS.times do |j|
116
+ yy = y[j]
117
+ if (rosen)
118
+ z[j,i] = pow(1 - xx, 2) + 100 * pow(yy - pow(xx, 2), 2)
119
+ # The log argument may be zero for just the right grid.
120
+ if (z[j,i] > 0)
121
+ z[j,i] = log(z[j,i])
122
+ else
123
+ z[j,i] = -5; # -MAXFLOAT would mess-up up the scale
124
+ end
125
+ else
126
+ r = sqrt(xx * xx + yy * yy)
127
+ z[j,i] = exp(-r * r) * cos(2.0 * PI * r)
128
+ end
129
+ end
130
+ end
131
+
132
+ # It would be convenient if narray had a minmax function
133
+ zmin = z.min
134
+ zmax = z.max
135
+
136
+ nlevel = LEVELS
137
+ step = (zmax-zmin)/(nlevel+1)
138
+ clevel = NArray.float(nlevel).indgen!(1).mul!(step).add!(zmin)
139
+
140
+ pllightsource(1,1,1)
141
+
142
+ 2.times do |k|
143
+ 4.times do |ifshade|
144
+ pladv(0)
145
+ plvpor(0.0, 1.0, 0.0, 0.9)
146
+ plwind(-1.0, 1.0, -0.9, 1.1)
147
+ plcol0(3)
148
+ plmtex("t", 1.0, 0.5, 0.5, title[k])
149
+ plcol0(1)
150
+ if (rosen)
151
+ plw3d(1.0, 1.0, 1.0, -1.5, 1.5, -0.5, 1.5, zmin, zmax, alt[k], az[k])
152
+ else
153
+ plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, zmin, zmax, alt[k], az[k])
154
+ end
155
+
156
+ plbox3("bnstu", "x axis", 0.0, 0,
157
+ "bnstu", "y axis", 0.0, 0,
158
+ "bcdmnstuv", "z axis", 0.0, 0)
159
+ plcol0(2)
160
+
161
+ if (ifshade == 0) # diffuse light surface plot
162
+ cmap1_init(1)
163
+ plsurf3d(x, y, z)
164
+ elsif (ifshade == 1) # magnitude colored plot
165
+ cmap1_init(0)
166
+ plsurf3d(x, y, z, PL::MAG_COLOR)
167
+ elsif (ifshade == 2) # magnitude colored plot with faceted squares
168
+ cmap1_init(0)
169
+ plsurf3d(x, y, z, PL::MAG_COLOR | PL::FACETED)
170
+ else # magnitude colored plot with contours
171
+ cmap1_init(0)
172
+ plsurf3d(x, y, z, PL::MAG_COLOR | PL::SURF_CONT | PL::BASE_CONT, clevel)
173
+ end
174
+ end
175
+ end
176
+
177
+ # Clean up
178
+
179
+ plend