Date:2011-01-18 09:21:06 (13 years 2 months ago)
Author:Xiangfu Liu
Commit:d3bb3a95be3cd729072fa880d8cd02353948873b
Message:add some lua-plplot-examples

Files: nanonote-example-files/files/lua-plplot-examples/plplot_examples.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x01.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x02.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x03.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x04.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x05.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x06.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x07.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x08.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x09.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x10.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x11.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x12.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x13.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x14.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x15.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x16.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x17.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x18.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x19.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x20.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x21.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x22.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x23.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x24.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x25.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x26.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x27.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x28.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x29.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x30.lua (1 diff)
nanonote-example-files/files/lua-plplot-examples/x31.lua (1 diff)

Change Details

nanonote-example-files/files/lua-plplot-examples/plplot_examples.lua
1-- initialise Lua bindings for PLplot examples.
2if string.sub(_VERSION,1,7)=='Lua 5.0' then
3    lib=loadlib('/home/pub/spock/src/qi/openwrt-xburst/build_dir/target-mipsel_uClibc-0.9.30.1/plplot-5.9.7/bindings/lua/plplotluac.so','luaopen_plplotluac') or
4      loadlib('/home/pub/spock/src/qi/openwrt-xburst/build_dir/target-mipsel_uClibc-0.9.30.1/plplot-5.9.7/bindings/lua/plplotluac.dll','luaopen_plplotluac') or
5      loadlib('/home/pub/spock/src/qi/openwrt-xburst/build_dir/target-mipsel_uClibc-0.9.30.1/plplot-5.9.7/bindings/lua/plplotluac.dylib','luaopen_plplotluac')
6    assert(lib)()
7else
8    package.cpath = '/home/pub/spock/src/qi/openwrt-xburst/build_dir/target-mipsel_uClibc-0.9.30.1/plplot-5.9.7/bindings/lua/?.so;' ..
9                  '/home/pub/spock/src/qi/openwrt-xburst/build_dir/target-mipsel_uClibc-0.9.30.1/plplot-5.9.7/bindings/lua/?.dll;' ..
10                  '/home/pub/spock/src/qi/openwrt-xburst/build_dir/target-mipsel_uClibc-0.9.30.1/plplot-5.9.7/bindings/lua/?.dylib;' ..package.cpath
11    require('plplotluac')
12end
nanonote-example-files/files/lua-plplot-examples/x01.lua
1--[[ $Id: x01.lua 9414 2009-01-29 22:48:54Z airwin $
2
3    Simple line plot and multiple windows demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27-- Variables and data arrays used by plot generators
28x = {}
29y = {}
30xs = {}
31ys = {}
32
33fontset = 1
34f_name = ""
35
36
37function plot1(do_test)
38  for i = 1, 60 do
39    x[i] = xoff + xscale * (i) / 60
40    y[i] = yoff + yscale * x[i]^2
41  end
42
43  xmin = x[1]
44  xmax = x[60]
45  ymin = y[1]
46  ymax = y[60]
47
48  for i = 1, 6 do
49    xs[i] = x[(i-1) * 10 + 4]
50    ys[i] = y[(i-1) * 10 + 4]
51  end
52
53  -- Set up the viewport and window using PLENV. The range in X is
54  -- 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are
55  -- scaled separately (just = 0), and we just draw a labelled
56  -- box (axis = 0).
57  pl.col0(1)
58  pl.env(xmin, xmax, ymin, ymax, 0, 0)
59  pl.col0(2)
60  pl.lab("(x)", "(y)", "#frPLplot Example 1 - y=x#u2")
61
62  -- Plot the data points
63  pl.col0(4)
64  pl.poin(xs, ys, 9)
65
66  -- Draw the line through the data
67  pl.col0(3)
68  pl.line(x, y)
69end
70
71
72function plot2()
73  -- Set up the viewport and window using PLENV. The range in X is -2.0 to
74  -- 10.0, and the range in Y is -0.4 to 2.0. The axes are scaled separately
75  --(just = 0), and we draw a box with axes (axis = 1).
76  pl.col0(1)
77  pl.env(-2, 10, -0.4, 1.2, 0, 1)
78  pl.col0(2)
79  pl.lab("(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function")
80
81  -- Fill up the arrays
82  for i=1, 100 do
83    x[i] = (i - 20) / 6
84    y[i] = 1
85    if x[i] ~= 0 then y[i] = math.sin(x[i])/x[i] end
86  end
87
88  -- Draw the line
89  pl.col0(3)
90  pl.wid(2)
91  pl.line(x, y)
92  pl.wid(1)
93end
94
95
96function plot3()
97  space0 = { }
98  mark0 = { }
99  space1 = { 1500 }
100  mark1 = { 1500 }
101
102  -- For the final graph we wish to override the default tick intervals, and
103  --so do not use plenv().
104  pl.adv(0)
105
106  -- Use standard viewport, and define X range from 0 to 360 degrees, Y range
107  --from -1.2 to 1.2.
108  pl.vsta()
109  pl.wind(0, 360, -1.2, 1.2)
110
111  -- Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y.
112  pl.col0(1)
113  pl.box("bcnst", 60, 2, "bcnstv", 0.2, 2)
114
115  -- Superimpose a dashed line grid, with 1.5 mm marks and spaces.
116  -- plstyl expects a pointer!
117  pl.styl(mark1, space1)
118  pl.col0(2)
119  pl.box("g", 30, 0, "g", 0.2, 0)
120  pl.styl(mark0, space0)
121
122  pl.col0(3)
123  pl.lab("Angle (degrees)", "sine", "#frPLplot Example 1 - Sine function")
124
125  for i=1, 101 do
126    x[i] = 3.6*(i-1)
127    y[i] = math.sin(x[i]*math.pi/180)
128  end
129
130  pl.col0(4)
131  pl.line(x, y)
132end
133
134
135----------------------------------------------------------------------------
136-- main
137--
138-- Generates several simple line plots. Demonstrates:
139-- - subwindow capability
140-- - setting up the window, drawing plot, and labelling
141-- - changing the color
142-- - automatic axis rescaling to exponential notation
143-- - placing the axes in the middle of the box
144-- - gridded coordinate axes
145----------------------------------------------------------------------------
146
147-- plplot initialization
148
149-- Parse and process command line arguments
150pl.parseopts(arg, pl.PL_PARSE_FULL)
151
152-- Get version number, just for kicks
153ver=pl.gver()
154print("PLplot library version: " .. ver)
155
156-- Initialize plplot
157-- Divide page into 2x2 plots
158-- Note: calling plstar replaces separate calls to plssub and plinit
159pl.star(2,2)
160
161-- Select font set as per input flag
162if fontset ~= 0 then
163    pl.fontld(1)
164else
165    pl.fontld(0)
166end
167
168-- Set up the data
169-- Original case
170xscale = 6
171yscale = 1
172xoff = 0
173yoff = 0
174
175-- Do a plot
176plot1(0)
177
178-- Set up the data
179xscale = 1
180yscale = 0.0014
181yoff = 0.0185
182
183-- Do a plot
184digmax = 5
185pl.syax(digmax, 0)
186
187plot1(1)
188plot2()
189plot3()
190
191-- Show how to save a plot:
192-- Open a new device, make it current, copy parameters,
193-- and replay the plot buffer
194if f_name~="" then -- command line option '-save filename'
195  print("The current plot was saved in color Postscript under the name " .. f_name .. ".\n")
196  cur_strm = pl.gstrm() -- get current stream
197  new_strm = pl.mkstrm() -- create a new one
198
199  pl.sfnam(f_name) -- file name
200  pl.sdev("psc") -- device type
201
202  pl.cpstrm(cur_strm, 0) -- copy old stream parameters to new stream
203  pl.replot() -- do the save by replaying the plot buffer
204  pl.plend1() -- finish the device
205
206  pl.sstrm(cur_strm) -- return to previous stream
207end
208
209-- Don't forget to call plend() to finish off!
210pl.plend()
nanonote-example-files/files/lua-plplot-examples/x02.lua
1--[[ $Id: x02.lua 9414 2009-01-29 22:48:54Z airwin $
2
3    Multiple window and color map 0 demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27----------------------------------------------------------------------------
28-- draw_windows
29--
30-- Draws a set of numbered boxes with colors according to cmap0 entry.
31----------------------------------------------------------------------------
32
33function draw_windows(nw, cmap0_offset)
34  pl.schr(0, 3.5)
35  pl.font(4)
36
37  for i = 0, nw-1 do
38    pl.col0(i+cmap0_offset)
39    pl.adv(0)
40    vmin = 0.1
41    vmax = 0.9
42    for j = 0, 2 do
43      pl.wid(j + 1)
44      pl.vpor(vmin, vmax, vmin, vmax)
45      pl.wind(0, 1, 0, 1)
46      pl.box("bc", 0, 0, "bc", 0, 0)
47      vmin = vmin + 0.1
48      vmax = vmax - 0.1
49    end
50    pl.wid(1)
51    pl.ptex(0.5, 0.5, 1, 0, 0.5, tostring(i))
52  end
53end
54
55
56----------------------------------------------------------------------------
57-- demo1
58--
59-- Demonstrates multipl.e windows and default color map 0 palette.
60----------------------------------------------------------------------------
61
62function demo1()
63  pl.bop()
64
65  -- Divide screen into 16 regions
66  pl.ssub(4, 4)
67
68  draw_windows(16, 0)
69
70  pl.eop()
71end
72
73
74----------------------------------------------------------------------------
75-- demo2
76--
77-- Demonstrates multipl.e windows, user-modified color map 0 palette, and
78-- HLS -> RGB translation.
79----------------------------------------------------------------------------
80
81function demo2()
82  -- Set up cmap0
83  -- Use 100 custom colors in addition to base 16
84  r = {}
85  g = {}
86  b = {}
87
88  -- Min & max lightness values
89  lmin = 0.15
90  lmax = 0.85
91
92  pl.bop()
93
94  -- Divide screen into 100 regions
95
96  pl.ssub(10, 10)
97
98  for i = 0, 99 do
99    -- Bounds on HLS, from pl.hlsrgb() commentary --
100    -- hue [0., 360.] degrees
101    -- lightness [0., 1.] magnitude
102    -- saturation [0., 1.] magnitude
103
104    -- Vary hue uniformly from left to right
105    h = (360/10) * math.mod(i, 10)
106
107    -- Vary lightness uniformly from top to bottom, between min & max
108    l = lmin + (lmax - lmin) * math.floor(i/10)/9
109
110    -- Use max saturation
111    s = 1
112
113    r1, g1, b1 = pl.hlsrgb(h, l, s)
114
115    -- Use 255.001 to avoid close truncation decisions in this example.
116    r[i+1+16] = r1 * 255.001
117    g[i+1+16] = g1 * 255.001
118    b[i+1+16] = b1 * 255.001
119  end
120
121  -- Load default cmap0 colors into our custom set
122  for i = 0, 15 do
123    r[i+1], g[i+1], b[i+1] = pl.gcol0(i)
124  end
125
126  -- Now set cmap0 all at once (faster, since fewer driver calls)
127  pl.scmap0(r, g, b)
128
129  draw_windows(100, 16)
130
131  pl.eop()
132end
133
134
135----------------------------------------------------------------------------
136-- main
137--
138-- Demonstrates multipl.e windows and color map 0 palette, both default and
139-- user-modified.
140----------------------------------------------------------------------------
141
142-- Parse and process command line arguments
143pl.parseopts(arg, pl.PL_PARSE_FULL)
144
145-- Initialize pl.pl.ot
146pl.init()
147
148-- Run demos
149demo1()
150demo2()
151
152pl.plend()
nanonote-example-files/files/lua-plplot-examples/x03.lua
1--[[ $Id: x03.lua 10613 2009-11-19 12:05:09Z andrewross $
2
3    Polar plot demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27----------------------------------------------------------------------------
28-- main
29--
30-- Generates polar plot, with 1-1 scaling.
31----------------------------------------------------------------------------
32
33x0 = {}
34y0 = {}
35x = {}
36y = {}
37
38dtr = math.pi/180
39for i = 1, 361 do
40  x0[i] = math.cos(dtr * (i-1))
41  y0[i] = math.sin(dtr * (i-1))
42end
43
44-- Parse and process command line arguments
45
46pl.parseopts(arg, pl.PL_PARSE_FULL)
47
48-- Set orientation to portrait - note not all device drivers
49-- support this, in particular most interactive drivers do not
50pl.sori(1)
51
52-- Initialize plplot
53pl.init()
54
55-- Set up viewport and window, but do not draw box
56pl.env(-1.3, 1.3, -1.3, 1.3, 1, -2)
57
58-- Draw circles for polar grid
59for i = 1, 10 do
60        pl.arc(0, 0, 0.1*i, 0.1*i, 0, 360, 0);
61end
62
63pl.col0(2)
64for i=1, 12 do
65    theta = 30 * (i-1)
66    dx = math.cos(dtr * theta)
67    dy = math.sin(dtr * theta)
68
69  -- Draw radial spokes for polar grid
70
71    pl.join(0, 0, dx, dy)
72
73  -- Write labels for angle
74    if theta < 9.99 then
75      offset = 0.45
76    else
77    if theta < 99.9 then
78      offset = 0.30
79    else
80      offset = 0.15
81    end
82    end
83
84  -- Slightly off zero to avoid floating point logic flips at 90 and 270 deg.
85    if dx >= -0.00001 then
86        pl.ptex(dx, dy, dx, dy, -offset, tostring(math.floor(theta)))
87    else
88        pl.ptex(dx, dy, -dx, -dy, 1.+offset, tostring(math.floor(theta)))
89  end
90end
91
92-- Draw the graph
93for i=1, 361 do
94  r = math.sin(dtr * (5*(i-1)))
95  x[i] = x0[i] * r
96  y[i] = y0[i] * r
97end
98pl.col0(3)
99pl.line(x, y)
100
101pl.col0(4)
102pl.mtex("t", 2, 0.5, 0.5, "#frPLplot Example 3 - r(#gh)=sin 5#gh")
103
104-- Close the plot at end
105pl.plend()
nanonote-example-files/files/lua-plplot-examples/x04.lua
1--[[ $Id: x04.lua 9414 2009-01-29 22:48:54Z airwin $
2
3    Log plot demo.
4    Simple line plot and multiple windows demo.
5
6  Copyright (C) 2008 Werner Smekal
7
8  This file is part of PLplot.
9
10  PLplot is free software you can redistribute it and/or modify
11  it under the terms of the GNU General Library Public License as published
12  by the Free Software Foundation either version 2 of the License, or
13  (at your option) any later version.
14
15  PLplot is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Library General Public License for more details.
19
20  You should have received a copy of the GNU Library General Public License
21  along with PLplot if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23--]]
24
25-- initialise Lua bindings for PLplot examples.
26dofile("plplot_examples.lua")
27
28----------------------------------------------------------------------------
29-- plot1
30--
31-- Log-linear plot.
32----------------------------------------------------------------------------
33
34function plot1(type)
35  freql = {}
36  ampl = {}
37  phase = {}
38
39  pl.adv(0)
40
41  -- Set up data for log plot
42  f0 = 1
43  for i=1, 101 do
44    freql[i] = -2 + (i-1) / 20
45    freq = 10^freql[i]
46    ampl[i] = 20 * math.log10(1 / math.sqrt(1 + (freq / f0)^2))
47    phase[i] = -(180 / math.pi) * math.atan(freq / f0)
48  end
49
50  pl.vpor(0.15, 0.85, 0.1, 0.9)
51  pl.wind(-2, 3, -80, 0)
52
53  -- Try different axis and labelling styles.
54  pl.col0(1)
55  if type == 0 then
56    pl.box("bclnst", 0, 0, "bnstv", 0, 0)
57  end
58
59  if type == 1 then
60    pl.box("bcfghlnst", 0, 0, "bcghnstv", 0, 0)
61  end
62
63  -- Plot ampl vs freq
64  pl.col0(2)
65  pl.line(freql, ampl)
66  pl.col0(1)
67  pl.ptex(1.6, -30, 1, -20, 0.5, "-20 dB/decade")
68
69  -- Put labels on
70  pl.col0(1)
71  pl.mtex("b", 3.2, 0.5, 0.5, "Frequency")
72  pl.mtex("t", 2, 0.5, 0.5, "Single Pole Low-Pass Filter")
73  pl.col0(2)
74  pl.mtex("l", 5, 0.5, 0.5, "Amplitude (dB)")
75
76  -- For the gridless case, put phase vs freq on same plot
77  if type == 0 then
78    pl.col0(1)
79    pl.wind(-2, 3, -100, 0)
80    pl.box("", 0, 0, "cmstv", 30, 3)
81    pl.col0(3)
82    pl.line(freql, phase)
83    pl.col0(3)
84    pl.mtex("r", 5, 0.5, 0.5, "Phase shift (degrees)")
85  end
86end
87
88
89----------------------------------------------------------------------------
90-- main
91--
92-- Illustration of logarithmic axes, and redefinition of window.
93----------------------------------------------------------------------------
94
95-- Parse and process command line arguments
96pl.parseopts(arg, pl.PL_PARSE_FULL)
97
98-- Initialize plplot
99pl.init()
100pl.font(2)
101
102-- Make log plots using two different styles.
103plot1(0)
104plot1(1)
105
106pl.plend()
nanonote-example-files/files/lua-plplot-examples/x05.lua
1--[[ $Id: x05.lua 9414 2009-01-29 22:48:54Z airwin $
2
3    Histogram demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27--------------------------------------------------------------------------
28-- main
29--
30-- Draws a histogram from sample data.
31--------------------------------------------------------------------------
32
33NPTS=2047
34data = {}
35
36-- Parse and process command line arguments
37pl.parseopts(arg, pl.PL_PARSE_FULL);
38
39-- Initialize plplot
40pl.init()
41
42-- Fill up data points
43delta = 2.0*math.pi/NPTS
44for i=1, NPTS do
45  data[i] = math.sin((i-1)*delta)
46end
47
48pl.col0(1)
49pl.hist(data, -1.1, 1.1, 44, 0)
50pl.col0(2)
51pl.lab("#frValue", "#frFrequency",
52         "#frPLplot Example 5 - Probability function of Oscillator")
53
54pl.plend()
nanonote-example-files/files/lua-plplot-examples/x06.lua
1--[[ $Id: x06.lua 11032 2010-05-27 22:34:40Z andrewross $
2
3    Font demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27----------------------------------------------------------------------------
28-- main
29--
30-- Displays the entire "plpoin" symbol (font) set.
31----------------------------------------------------------------------------
32
33-- Parse and process command line arguments
34pl.parseopts(arg, pl.PL_PARSE_FULL)
35
36-- Initialize plplot
37pl.init()
38
39for kind_font = 0,1 do
40  pl.fontld( kind_font )
41  if kind_font == 0 then
42    maxfont = 1
43  else
44    maxfont = 4
45  end
46
47  for font = 1,maxfont do
48    pl.font( font )
49    pl.adv(0)
50
51    -- Set up viewport and window
52    pl.col0(2)
53    pl.vpor(0.1, 1, 0.1, 0.9)
54    pl.wind(0, 1, 0, 1.3)
55
56    -- Draw the grid using plbox
57    pl.box("bcg", 0.1, 0, "bcg", 0.1, 0)
58
59    -- Write the digits below the frame
60    pl.col0(15)
61    for i=0, 9 do
62      pl.mtex("b", 1.5, (0.1 * i + 0.05), 0.5, tostring(i))
63    end
64
65    k = 0
66    x = {}
67    y ={}
68    for i = 0, 12 do
69      -- Write the digits to the left of the frame
70      pl.mtex("lv", 1, (1 - (2 * i + 1) / 26), 1, tostring(10*i))
71      for j = 0, 9 do
72        x[1] = 0.1 * j + 0.05
73        y[1] = 1.25 - 0.1 * i
74
75        -- Display the symbols
76        if k < 128 then
77          pl.poin(x, y, k)
78        end
79        k = k + 1
80      end
81    end
82
83    if kind_font == 0 then
84      pl.mtex("t", 1.5, 0.5, 0.5, "PLplot Example 6 - plpoin symbols (compact)")
85    else
86      pl.mtex("t", 1.5, 0.5, 0.5, "PLplot Example 6 - plpoin symbols (extended)")
87    end
88  end
89end
90pl.plend()
nanonote-example-files/files/lua-plplot-examples/x07.lua
1--[[ $Id: x07.lua 11032 2010-05-27 22:34:40Z andrewross $
2
3    Font demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27base = { 0, 100, 0, 100, 200, 500, 600, 700, 800, 900,
28         2000, 2100, 2200, 2300, 2400, 2500,
29                 2600, 2700, 2800, 2900 }
30
31----------------------------------------------------------------------------
32-- main
33--
34-- Displays the entire "plsym" symbol (font) set.
35----------------------------------------------------------------------------
36
37-- Parse and process command line arguments
38pl.parseopts(arg, pl.PL_PARSE_FULL)
39
40-- Initialize plplot
41pl.init()
42
43pl.fontld(0)
44for l = 1, 20 do
45
46    if l == 3 then
47        pl.fontld(1)
48    end
49    pl.adv(0)
50
51    -- Set up viewport and window
52    pl.col0(2)
53    pl.vpor(0.15, 0.95, 0.1, 0.9)
54    pl.wind(0, 1, 0, 1)
55
56    -- Draw the grid using plbox
57
58    pl.box("bcg", 0.1, 0, "bcg", 0.1, 0)
59
60    -- Write the digits below the frame
61
62    pl.col0(15)
63    for i = 0, 9 do
64        pl.mtex("b", 1.5, (0.1 * i + 0.05), 0.5, tostring(i))
65    end
66
67    k = 0
68    x = {}
69    y = {}
70    for i = 0, 9 do
71        -- Write the digits to the left of the frame
72        pl.mtex("lv", 1.0, (0.95 - 0.1 * i), 1.0, tostring(base[l] + 10 * i))
73        for j=0, 9 do
74            x[1] = 0.1 * j + 0.05
75            y[1] = 0.95 - 0.1 * i
76
77            -- Display the symbols
78            pl.sym(x, y, base[l] + k)
79            k = k + 1
80        end
81    end
82
83    if l <= 2 then
84        pl.mtex("t", 1.5, 0.5, 0.5, "PLplot Example 7 - PLSYM symbols (compact)")
85    else
86        pl.mtex("t", 1.5, 0.5, 0.5, "PLplot Example 7 - PLSYM symbols (extended)")
87    end
88end
89
90pl.plend()
nanonote-example-files/files/lua-plplot-examples/x08.lua
1--[[ $Id: x08.lua 9533 2009-02-16 22:18:37Z smekal $
2
3    3-d plot demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27
28-- bitwise or operator from http://lua-users.org/wiki/BaseSixtyFour
29-- (c) 2006-2008 by Alex Kloss
30-- licensed under the terms of the LGPL2
31
32-- return single bit (for OR)
33function bit(x,b)
34    return (math.mod(x, 2^b) - math.mod(x,2^(b-1)) > 0)
35end
36
37-- logic OR for number values
38function lor(x,y)
39    result = 0
40    for p=1,8 do result = result + (((bit(x,p) or bit(y,p)) == true) and 2^(p-1) or 0) end
41    return result
42end
43
44
45----------------------------------------------------------------------------
46-- cmap1_init1
47--
48-- Initializes color map 1 in HLS space.
49-- Basic grayscale variation from half-dark (which makes more interesting
50-- looking plot compared to dark) to light.
51-- An interesting variation on this:
52-- s[1] = 1.0
53----------------------------------------------------------------------------
54
55function cmap1_init(gray)
56  i = { 0, 1 } -- left and right boundary
57
58  if gray ~= 0 then
59    h = { 0, 0 } -- hue -- low: red (arbitrary if s=0), high: red (arbitrary if s=0)
60    l = { 0.5, 1 } -- lightness -- low: half-dark, high: light
61    s = { 0, 0 } -- minimum saturation
62  else
63    h = { 240, 0 } -- blue -> green -> yellow -> red
64    l = { 0.6, 0.6 }
65    s = { 0.8, 0.8 }
66  end
67
68  pl.scmap1n(256)
69  pl.scmap1l(0, i, h, l, s)
70end
71
72
73----------------------------------------------------------------------------
74-- main
75--
76-- Does a series of 3-d plots for a given data set, with different
77-- viewing options in each plot.
78----------------------------------------------------------------------------
79
80XPTS = 35 -- Data points in x
81YPTS = 46 -- Data points in y
82LEVELS = 10
83
84alt = { 60, 20 }
85az = { 30, 60 }
86
87title = {
88    "#frPLplot Example 8 - Alt=60, Az=30",
89    "#frPLplot Example 8 - Alt=20, Az=60"
90}
91
92clevel = {}
93nlevel = LEVELS
94rosen = 1
95sombrero = 0
96
97-- Parse and process command line arguments
98pl.parseopts(arg, pl.PL_PARSE_FULL)
99if sombrero ~= 0 then rosen=0 end
100
101-- Initialize plplot
102pl.init()
103
104-- Allocate data structures
105x = {}
106y = {}
107z = {}
108
109for i=1, XPTS do
110  x[i] = (i-1-math.floor(XPTS/2)) / math.floor(XPTS/2)
111  if rosen~=0 then x[i]=x[i]*1.5 end
112end
113
114for i=1, YPTS do
115  y[i] = (i-1-math.floor(YPTS/2)) / math.floor(YPTS/2)
116  if rosen~=0 then y[i]=y[i]+0.5 end
117end
118
119for i=1, XPTS do
120  xx = x[i]
121  z[i]= {}
122  for j=1, YPTS do
123    yy = y[j]
124    if rosen~=0 then
125      z[i][j] = (1-xx)^2 + 100*(yy-xx^2)^2
126      -- The log argument may be zero for just the right grid.
127      if z[i][j] > 0 then
128        z[i][j] = math.log(z[i][j])
129      else
130        z[i][j] = -5 -- MAXFLOAT would mess-up up the scale
131      end
132    else
133      r = math.sqrt(xx^2 + yy^2)
134      z[i][j] = math.exp(-r^2) * math.cos(2*math.pi*r)
135    end
136  end
137end
138
139zmax, zmin = pl.MinMax2dGrid(z)
140step = (zmax-zmin)/(nlevel+1)
141for i=1, nlevel do
142  clevel[i] = zmin + step + step*(i-1)
143end
144
145pl.lightsource(1, 1, 1)
146
147for k=1, 2 do
148  for ifshade = 1, 4 do
149    pl.adv(0)
150    pl.vpor(0, 1, 0, 0.9)
151    pl.wind(-1, 1, -0.9, 1.1)
152    pl.col0(3)
153    pl.mtex("t", 1, 0.5, 0.5, title[k])
154    pl.col0(1)
155    if rosen~=0 then
156      pl.w3d(1, 1, 1, -1.5, 1.5, -0.5, 1.5, zmin, zmax, alt[k], az[k])
157    else
158      pl.w3d(1, 1, 1, -1, 1, -1, 1, zmin, zmax, alt[k], az[k])
159    end
160
161    pl.box3("bnstu", "x axis", 0, 0,
162           "bnstu", "y axis", 0, 0,
163           "bcdmnstuv", "z axis", 0, 0)
164    pl.col0(2)
165
166    if ifshade==1 then -- diffuse light surface plot
167      cmap1_init(1)
168      pl.surf3d(x, y, z, 0, clevel)
169    end
170
171    if ifshade==2 then -- magnitude colored plot
172      cmap1_init(0)
173      pl.surf3d(x, y, z, pl.MAG_COLOR, {})
174    end
175
176    if ifshade==3 then -- magnitude colored plot with faceted squares
177      cmap1_init(0)
178      pl.surf3d(x, y, z, lor(pl.MAG_COLOR, pl.FACETED), {})
179    end
180
181    if ifshade==4 then -- magnitude colored plot with contours
182      cmap1_init(0)
183      pl.surf3d(x, y, z, lor(lor(pl.MAG_COLOR, pl.SURF_CONT), pl.BASE_CONT), clevel)
184    end
185  end
186end
187
188-- Clean up
189pl.plend()
nanonote-example-files/files/lua-plplot-examples/x09.lua
1--[[ $Id: x09.lua 9533 2009-02-16 22:18:37Z smekal $
2
3    Contour plot demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27XPTS = 35 -- Data points in x
28YPTS = 46 -- Data points in y
29
30XSPA = 2/(XPTS-1)
31YSPA = 2/(YPTS-1)
32
33-- polar plot data
34PERIMETERPTS = 100
35RPTS = 40
36THETAPTS = 40
37
38-- potential plot data
39PPERIMETERPTS = 100
40PRPTS = 40
41PTHETAPTS = 64
42PNLEVEL = 20
43
44clevel = { -1, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8, 1}
45
46-- Transformation function
47tr = { XSPA, 0, -1, 0, YSPA, -1 }
48
49function mypltr(x, y)
50    tx = tr[1] * x + tr[2] * y + tr[3]
51    ty = tr[4] * x + tr[5] * y + tr[6]
52
53    return tx, ty
54end
55
56--polar contour plot example.
57function polar()
58    px = {}
59    py = {}
60    lev = {}
61
62    pl.env(-1, 1, -1, 1, 0, -2)
63    pl.col0(1)
64
65    --Perimeter
66    for i=1, PERIMETERPTS do
67        t = (2*math.pi/(PERIMETERPTS-1))*(i-1)
68        px[i] = math.cos(t)
69        py[i] = math.sin(t)
70  end
71  pl.line(px, py)
72
73    --create data to be contoured.
74  cgrid2["xg"] = {}
75  cgrid2["yg"] = {}
76  cgrid2["nx"] = RPTS
77  cgrid2["ny"] = THETAPTS
78  z = {}
79
80  for i = 1, RPTS do
81    r = (i-1)/(RPTS-1)
82    cgrid2["xg"][i] = {}
83    cgrid2["yg"][i] = {}
84    z[i] = {}
85    for j = 1, THETAPTS do
86      theta = (2*math.pi/(THETAPTS-1))*(j-1)
87      cgrid2["xg"][i][j] = r*math.cos(theta)
88      cgrid2["yg"][i][j] = r*math.sin(theta)
89      z[i][j] = r
90    end
91  end
92
93  for i = 1, 10 do
94    lev[i] = 0.05 + 0.10*(i-1)
95  end
96
97  pl.col0(2)
98  pl.cont(z, 1, RPTS, 1, THETAPTS, lev, "pltr2", cgrid2)
99  pl.col0(1)
100  pl.lab("", "", "Polar Contour Plot")
101end
102
103
104----------------------------------------------------------------------------
105-- f2mnmx
106--
107-- Returns min & max of input 2d array.
108----------------------------------------------------------------------------
109function f2mnmx(f, nx, ny)
110    fmax = f[1][1]
111    fmin = fmax
112
113    for i=1, nx do
114        for j=1, ny do
115        fmax = math.max(fmax, f[i][j])
116        fmin = math.min(fmin, f[i][j])
117        end
118    end
119
120    return fmin, fmax
121end
122
123
124--shielded potential contour plot example.
125function potential()
126  clevelneg = {}
127  clevelpos = {}
128  px = {}
129  py = {}
130
131  --create data to be contoured.
132  cgrid2["xg"] = {}
133  cgrid2["yg"] = {}
134  cgrid2["nx"] = PRPTS
135  cgrid2["ny"] = PTHETAPTS
136  z = {}
137
138  for i = 1, PRPTS do
139    r = 0.5 + (i-1)
140    cgrid2["xg"][i] = {}
141    cgrid2["yg"][i] = {}
142    for j = 1, PTHETAPTS do
143      theta = 2*math.pi/(PTHETAPTS-1)*(j-0.5)
144      cgrid2["xg"][i][j] = r*math.cos(theta)
145      cgrid2["yg"][i][j] = r*math.sin(theta)
146    end
147  end
148
149  rmax = PRPTS-0.5
150  xmin, xmax = f2mnmx(cgrid2["xg"], PRPTS, PTHETAPTS)
151  ymin, ymax = f2mnmx(cgrid2["yg"], PRPTS, PTHETAPTS)
152  x0 = (xmin + xmax)/2
153  y0 = (ymin + ymax)/2
154
155  -- Expanded limits
156  peps = 0.05
157  xpmin = xmin - math.abs(xmin)*peps
158  xpmax = xmax + math.abs(xmax)*peps
159  ypmin = ymin - math.abs(ymin)*peps
160  ypmax = ymax + math.abs(ymax)*peps
161
162  -- Potential inside a conducting cylinder (or sphere) by method of images.
163  -- Charge 1 is placed at (d1, d1), with image charge at (d2, d2).
164  -- Charge 2 is placed at (d1, -d1), with image charge at (d2, -d2).
165  -- Also put in smoothing term at small distances.
166  eps = 2
167  q1 = 1
168  d1 = rmax/4
169
170  q1i = - q1*rmax/d1
171  d1i = rmax^2/d1
172
173  q2 = -1
174  d2 = rmax/4
175
176  q2i = - q2*rmax/d2
177  d2i = rmax^2/d2
178
179  for i = 1, PRPTS do
180    z[i] = {}
181    for j = 1, PTHETAPTS do
182      div1 = math.sqrt((cgrid2.xg[i][j]-d1)^2 + (cgrid2.yg[i][j]-d1)^2 + eps^2)
183      div1i = math.sqrt((cgrid2.xg[i][j]-d1i)^2 + (cgrid2.yg[i][j]-d1i)^2 + eps^2)
184      div2 = math.sqrt((cgrid2.xg[i][j]-d2)^2 + (cgrid2.yg[i][j]+d2)^2 + eps^2)
185      div2i = math.sqrt((cgrid2.xg[i][j]-d2i)^2 + (cgrid2.yg[i][j]+d2i)^2 + eps^2)
186      z[i][j] = q1/div1 + q1i/div1i + q2/div2 + q2i/div2i
187    end
188  end
189  zmin, zmax = f2mnmx(z, PRPTS, PTHETAPTS)
190
191  -- Positive and negative contour levels.
192  dz = (zmax-zmin)/PNLEVEL
193  nlevelneg = 1
194  nlevelpos = 1
195  for i = 1, PNLEVEL do
196    clevel = zmin + (i-0.5)*dz
197    if clevel <= 0 then
198      clevelneg[nlevelneg] = clevel
199      nlevelneg = nlevelneg + 1
200    else
201      clevelpos[nlevelpos] = clevel
202      nlevelpos = nlevelpos + 1
203    end
204  end
205
206  -- Colours!
207  ncollin = 11
208  ncolbox = 1
209  ncollab = 2
210
211  -- Finally start plotting this page!
212  pl.adv(0)
213  pl.col0(ncolbox)
214
215  pl.vpas(0.1, 0.9, 0.1, 0.9, 1)
216  pl.wind(xpmin, xpmax, ypmin, ypmax)
217  pl.box("", 0, 0, "", 0, 0)
218
219  pl.col0(ncollin)
220  if nlevelneg>1 then
221    -- Negative contours
222    pl.lsty(2)
223    pl.cont(z, 1, PRPTS, 1, PTHETAPTS, clevelneg, "pltr2", cgrid2)
224  end
225
226  if nlevelpos>1 then
227    -- Positive contours
228    pl.lsty(1)
229    pl.cont(z, 1, PRPTS, 1, PTHETAPTS, clevelpos, "pltr2", cgrid2)
230  end
231
232  -- Draw outer boundary
233  for i = 1, PPERIMETERPTS do
234    t = (2*math.pi/(PPERIMETERPTS-1))*(i-1)
235    px[i] = x0 + rmax*math.cos(t)
236    py[i] = y0 + rmax*math.sin(t)
237  end
238
239  pl.col0(ncolbox)
240  pl.line(px, py)
241
242  pl.col0(ncollab)
243  pl.lab("", "", "Shielded potential of charges in a conducting sphere")
244end
245
246
247----------------------------------------------------------------------------
248-- main
249--
250-- Does several contour plots using different coordinate mappings.
251----------------------------------------------------------------------------
252mark = { 1500 }
253space = { 1500 }
254
255-- Parse and process command line arguments
256pl.parseopts(arg, pl.PL_PARSE_FULL)
257
258-- Initialize plplot
259pl.init()
260
261-- Set up function arrays
262z = {}
263w = {}
264
265for i = 1, XPTS do
266    xx = (i-1 - math.floor(XPTS/2)) / math.floor(XPTS/2)
267  z[i] = {}
268  w[i] = {}
269    for j = 1, YPTS do
270        yy = (j-1 - math.floor(YPTS/2)) / math.floor(YPTS/2) - 1
271        z[i][j] = xx^2 - yy^2
272        w[i][j] = 2 * xx * yy
273    end
274end
275
276-- Set up grids
277cgrid1 = {}
278cgrid1["xg"] = {}
279cgrid1["yg"] = {}
280cgrid1["nx"] = XPTS
281cgrid1["ny"] = YPTS
282cgrid2 = {}
283cgrid2["xg"] = {}
284cgrid2["yg"] = {}
285cgrid2["nx"] = XPTS
286cgrid2["ny"] = YPTS
287
288for i = 1, XPTS do
289  cgrid2["xg"][i] = {}
290  cgrid2["yg"][i] = {}
291    for j = 1, YPTS do
292    xx, yy = mypltr(i-1, j-1)
293
294    argx = xx * math.pi/2
295    argy = yy * math.pi/2
296    distort = 0.4
297
298    cgrid1["xg"][i] = xx + distort * math.cos(argx)
299    cgrid1["yg"][j] = yy - distort * math.cos(argy)
300
301    cgrid2["xg"][i][j] = xx + distort * math.cos(argx) * math.cos(argy)
302    cgrid2["yg"][i][j] = yy - distort * math.cos(argx) * math.cos(argy)
303  end
304end
305
306-- Plot using identity transform
307pl.setcontlabelformat(4, 3)
308pl.setcontlabelparam(0.006, 0.3, 0.1, 1)
309pl.env(-1, 1, -1, 1, 0, 0)
310pl.col0(2)
311pl.cont(z, 1, XPTS, 1, YPTS, clevel, "mypltr")
312pl.styl(mark, space)
313pl.col0(3)
314pl.cont(w, 1, XPTS, 1, YPTS, clevel, "mypltr")
315pl.styl({}, {})
316pl.col0(1)
317pl.lab("X Coordinate", "Y Coordinate", "Streamlines of flow")
318pl.setcontlabelparam(0.006, 0.3, 0.1, 0)
319
320-- Plot using 1d coordinate transform
321pl.env(-1, 1, -1, 1, 0, 0)
322pl.col0(2)
323pl.cont(z, 1, XPTS, 1, YPTS, clevel, "pltr1", cgrid1)
324pl.styl(mark, space)
325pl.col0(3)
326pl.cont(w, 1, XPTS, 1, YPTS, clevel, "pltr1", cgrid1)
327pl.styl({}, {})
328pl.col0(1)
329pl.lab("X Coordinate", "Y Coordinate", "Streamlines of flow")
330
331-- Plot using 2d coordinate transform
332pl.env(-1, 1, -1, 1, 0, 0)
333pl.col0(2)
334pl.cont(z, 1, XPTS, 1, YPTS, clevel, "pltr2", cgrid2)
335
336pl.styl(mark, space)
337pl.col0(3)
338pl.cont(w, 1, XPTS, 1, YPTS, clevel, "pltr2", cgrid2)
339pl.styl({}, {})
340pl.col0(1)
341pl.lab("X Coordinate", "Y Coordinate", "Streamlines of flow")
342
343pl.setcontlabelparam(0.006, 0.3, 0.1, 0)
344polar()
345
346pl.setcontlabelparam(0.006, 0.3, 0.1, 0)
347potential()
348
349-- Clean up
350pl.plend()
nanonote-example-files/files/lua-plplot-examples/x10.lua
1--[[ $Id: x10.lua 9414 2009-01-29 22:48:54Z airwin $
2
3    Window positioning demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27
28----------------------------------------------------------------------------
29-- main
30--
31-- Demonstrates absolute positioning of graphs on a page.
32----------------------------------------------------------------------------
33
34-- Parse and process command line arguments
35pl.parseopts(arg, pl.PL_PARSE_FULL);
36
37-- Initialize plplot
38pl.init()
39
40pl.adv(0)
41pl.vpor(0.0, 1.0, 0.0, 1.0)
42pl.wind(0.0, 1.0, 0.0, 1.0)
43pl.box("bc", 0.0, 0, "bc", 0.0, 0)
44
45pl.svpa(50.0, 150.0, 50.0, 100.0)
46pl.wind(0.0, 1.0, 0.0, 1.0)
47pl.box("bc", 0.0, 0, "bc", 0.0, 0)
48pl.ptex(0.5, 0.5, 1.0, 0.0, 0.5, "BOX at (50,150,50,100)")
49pl.plend()
nanonote-example-files/files/lua-plplot-examples/x11.lua
1--[[ $Id: x11.lua 9533 2009-02-16 22:18:37Z smekal $
2
3    Mesh plot demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27XPTS = 35 -- Data points in x
28YPTS = 46 -- Data points in y
29LEVELS = 10
30
31opt = { pl.DRAW_LINEXY, pl.DRAW_LINEXY }
32
33alt = { 33, 17 }
34az = { 24, 115 }
35
36title = {
37    "#frPLplot Example 11 - Alt=33, Az=24, Opt=3",
38    "#frPLplot Example 11 - Alt=17, Az=115, Opt=3" }
39
40
41-- bitwise or operator from http://lua-users.org/wiki/BaseSixtyFour
42-- (c) 2006-2008 by Alex Kloss
43-- licensed under the terms of the LGPL2
44
45-- return single bit (for OR)
46function bit(x,b)
47    return (math.mod(x, 2^b) - math.mod(x,2^(b-1)) > 0)
48end
49
50-- logic OR for number values
51function lor(x,y)
52    result = 0
53    for p=1,8 do result = result + (((bit(x,p) or bit(y,p)) == true) and 2^(p-1) or 0) end
54    return result
55end
56
57
58function cmap1_init()
59  i = { 0, 1 } -- left boundary , right boundary
60  h = { 240, 0 } -- blue -> green -> yellow -> red
61  l = { 0.6, 0.6 }
62  s = { 0.8, 0.8 }
63
64  pl.scmap1n(256)
65  pl.scmap1l(0, i, h, l, s)
66end
67
68
69----------------------------------------------------------------------------
70-- main
71--
72-- Does a series of mesh plots for a given data set, with different
73-- viewing options in each plot.
74----------------------------------------------------------------------------
75
76nlevel = LEVELS
77clevel = {}
78
79-- Parse and process command line arguments
80pl.parseopts(arg, pl.PL_PARSE_FULL)
81
82-- Initialize plplot
83pl.init()
84
85x = {}
86y = {}
87z = {}
88
89for i=1, XPTS do
90  x[i] = 3 * (i-1-math.floor(XPTS/2)) / math.floor(XPTS/2)
91end
92
93for i=1, YPTS do
94  y[i] = 3 * (i-1-math.floor(YPTS/2)) / math.floor(YPTS/2)
95end
96
97for i=1, XPTS do
98  xx = x[i]
99  z[i] = {}
100  for j=1, YPTS do
101    yy = y[j]
102    z[i][j] = 3 * (1-xx)^2 * math.exp(-xx^2 - (yy+1.)^2) -
103              10 * (xx/5 - xx^3 - yy^5) * math.exp(-xx^2-yy^2) -
104              1/3 * math.exp(-(xx+1)^2 - yy^2)
105
106    -- Jungfraujoch/Interlaken
107    if false then
108      if z[i][j] < -1 then z[i][j] = -1 end
109    end
110  end
111end
112
113zmax, zmin = pl.MinMax2dGrid(z)
114step = (zmax - zmin)/(nlevel+1)
115for i=1, nlevel do
116  clevel[i] = zmin + step + step*(i-1)
117end
118
119cmap1_init()
120for k=1, 2 do
121  for i=1, 4 do
122    pl.adv(0)
123    pl.col0(1)
124    pl.vpor(0, 1, 0, 0.9)
125    pl.wind(-1, 1, -1, 1.5)
126    pl.w3d(1, 1, 1.2, -3, 3, -3, 3, zmin, zmax, alt[k], az[k])
127    pl.box3("bnstu", "x axis", 0, 0,
128            "bnstu", "y axis", 0, 0,
129            "bcdmnstuv", "z axis", 0, 4)
130
131    pl.col0(2)
132
133    -- wireframe plot
134    if i==1 then
135      pl.mesh(x, y, z, opt[k])
136    end
137
138    -- magnitude colored wireframe plot
139    if i==2 then
140      pl.mesh(x, y, z, lor(opt[k], pl.MAG_COLOR))
141    end
142
143    -- magnitude colored wireframe plot with sides
144    if i==3 then
145      pl.plot3d(x, y, z, lor(opt[k], pl.MAG_COLOR), 1)
146    end
147
148    -- magnitude colored wireframe plot with base contour
149    if i==4 then
150      pl.meshc(x, y, z, lor(lor(opt[k], pl.MAG_COLOR), pl.BASE_CONT), clevel)
151    end
152
153    pl.col0(3)
154    pl.mtex("t", 1, 0.5, 0.5, title[k])
155  end
156end
157
158-- Clean up
159
160pl.plend()
nanonote-example-files/files/lua-plplot-examples/x12.lua
1--[[ $Id: x12.lua 9533 2009-02-16 22:18:37Z smekal $
2
3    Bar chart demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27function pl.fbox(x0, y0)
28  x = { x0, x0, x0+1,x0+1 }
29  y = { 0, y0, y0, 0 }
30
31  pl.fill(x, y);
32  pl.col0(1);
33  pl.lsty(1);
34  pl.line(x, y);
35end
36
37--------------------------------------------------------------------------
38-- main
39--
40-- Does a simple bar chart, using color fill. If color fill is
41-- unavailable, pattern fill is used instead (automatic).
42--------------------------------------------------------------------------
43
44y0 = {}
45
46pos = { 0, 0.25, 0.5, 0.75, 1 }
47red = { 0, 0.25, 0.5, 1, 1 }
48green = { 1, 0.5, 0.5, 0.5, 1 }
49blue = { 1, 1, 0.5, 0.25, 0 }
50
51
52-- Parse and process command line arguments
53
54pl.parseopts(arg, pl.PL_PARSE_FULL);
55
56-- Initialize plplot
57pl.init()
58
59pl.adv(0)
60pl.vsta()
61pl.wind(1980, 1990, 0, 35)
62pl.box("bc", 1, 0, "bcnv", 10, 0)
63pl.col0(2)
64pl.lab("Year", "Widget Sales (millions)", "#frPLplot Example 12")
65
66y0 = { 5, 15, 12, 24, 28, 30, 20, 8, 12, 3}
67
68pl.scmap1l(1, pos, red, green, blue);
69
70for i=1, 10 do
71    pl.col1((i-1)/9.0);
72    pl.psty(0);
73    pl.fbox((1980+i-1), y0[i]);
74    pl.ptex((1980+i-0.5), (y0[i]+1), 1, 0, 0.5, tostring(y0[i]));
75    pl.mtex("b", 1, (i*0.1-0.05), 0.5, tostring(1980+i-1));
76end
77
78pl.plend();
nanonote-example-files/files/lua-plplot-examples/x13.lua
1--[[ $Id: x13.lua 9526 2009-02-13 22:06:13Z smekal $
2
3    Pie chart demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27text = { "Maurice", "Geoffrey", "Alan",
28         "Rafael", "Vince" }
29
30--------------------------------------------------------------------------
31-- main
32--
33-- Does a simple pie chart.
34--------------------------------------------------------------------------
35
36per = { 10, 32, 12, 30, 16 }
37
38-- Parse and process command line arguments
39
40pl.parseopts(arg, pl.PL_PARSE_FULL);
41
42-- Initialize plplot
43
44pl.init()
45
46pl.adv(0)
47
48-- Ensure window has aspect ratio of one so circle is
49-- plotted as a circle.
50pl.vasp(1)
51pl.wind(0, 10, 0, 10)
52pl.col0(2)
53
54-- n.b. all theta quantities scaled by 2*M_PI/500 to be integers to avoid
55--floating point logic problems.
56theta0 = 0
57dthet = 1
58for i = 1, 5 do
59  x = { 5 }
60  y = { 5 }
61  j = 2
62  -- n.b. the theta quantities multiplied by 2*math.pi/500 afterward so
63  -- in fact per is interpreted as a percentage.
64    theta1 = theta0 + 5 * per[i]
65    if i == 5 then theta1 = 500 end
66
67    for theta = theta0, theta1, dthet do
68        x[j] = 5 + 3 * math.cos(2*math.pi/500*theta)
69        y[j] = 5 + 3 * math.sin(2*math.pi/500*theta)
70      j = j + 1
71      thetasave=theta
72    end
73    pl.col0(i)
74    pl.psty(math.mod((i + 2), 8) + 1)
75    pl.fill(x, y)
76    pl.col0(1)
77    pl.line(x, y)
78    just = 2*math.pi/500*(theta0 + theta1)/2
79    dx = 0.25 * math.cos(just)
80    dy = 0.25 * math.sin(just)
81    if (theta0 + theta1)<250 or (theta0 + theta1)>750 then
82      just = 0
83    else
84    just = 1
85  end
86
87    pl.ptex((x[(j-1)/2+1] + dx), (y[(j-1)/2+1] + dy), 1, 0, just, text[i]);
88    theta0 = thetasave
89end
90
91pl.font(2)
92pl.schr(0, 1.3)
93pl.ptex(5, 9, 1, 0, 0.5, "Percentage of Sales")
94
95pl.plend()
96
nanonote-example-files/files/lua-plplot-examples/x14.lua
1--[[ $Id: x14.lua 10793 2010-02-06 01:48:39Z hbabcock $
2
3    Demo of multiple stream/window capability (requires Tk or Tcl-DP).
4
5    Maurice LeBrun
6    IFS, University of Texas at Austin
7
8   Copyright (C) 2009 Werner Smekal
9
10   This file is part of PLplot.
11
12   PLplot is free software you can redistribute it and/or modify
13   it under the terms of the GNU General Library Public License as published
14   by the Free Software Foundation either version 2 of the License, or
15   (at your option) any later version.
16
17   PLplot is distributed in the hope that it will be useful,
18   but WITHOUT ANY WARRANTY without even the implied warranty of
19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20   GNU Library General Public License for more details.
21
22   You should have received a copy of the GNU Library General Public License
23   along with PLplot if not, write to the Free Software
24   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25--]]
26
27-- initialise Lua bindings for PLplot examples.
28dofile("plplot_examples.lua")
29
30xs = {}
31ys = {}
32space0 = {}
33mark0 = {}
34space1 = { 1500 }
35mark1 = { 1500 }
36
37
38function plot1()
39  x = {}
40  y = {}
41
42  for i = 1, 60 do
43    x[i] = xoff + xscale*i/60
44    y[i] = yoff + yscale*x[i]^2
45  end
46
47  xmin = x[1]
48  xmax = x[60]
49  ymin = y[1]
50  ymax = y[60]
51
52  for i = 1, 6 do
53    xs[i] = x[(i-1)*10 + 4]
54    ys[i] = y[(i-1)*10 + 4]
55  end
56
57  -- Set up the viewport and window using PLENV. The range in X is
58  -- 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are
59  -- scaled separately (just = 0), and we just draw a labelled
60  -- box (axis = 0).
61  pl.col0(1)
62  pl.env(xmin, xmax, ymin, ymax, 0, 0)
63  pl.col0(6)
64  pl.lab("(x)", "(y)", "#frPLplot Example 1 - y=x#u2")
65
66  -- Plot the data points
67  pl.col0(9)
68  pl.poin(xs, ys, 9)
69
70  -- Draw the line through the data
71  pl.col0(4)
72  pl.line(x, y)
73  pl.flush()
74end
75
76
77function plot2()
78  x = {}
79  y = {}
80
81  -- Set up the viewport and window using PLENV. The range in X is -2.0 to
82  -- 10.0, and the range in Y is -0.4 to 2.0. The axes are scaled separately
83  -- (just = 0), and we draw a box with axes (axis = 1).
84  pl.col0(1)
85  pl.env(-2, 10, -0.4, 1.2, 0, 1)
86  pl.col0(2)
87  pl.lab("(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function")
88
89  -- Fill up the arrays
90  for i = 1, 100 do
91    x[i] = (i-20)/6
92    y[i] = 1
93    if x[i]~=0 then
94      y[i] = math.sin(x[i])/x[i]
95    end
96  end
97
98  -- Draw the line
99  pl.col0(3)
100  pl.line(x, y)
101  pl.flush()
102end
103
104
105function plot3()
106  x = {}
107  y = {}
108
109  -- For the final graph we wish to override the default tick intervals, and
110  -- so do not use PLENV
111  pl.adv(0)
112
113  -- Use standard viewport, and define X range from 0 to 360 degrees, Y range
114  -- from -1.2 to 1.2.
115  pl.vsta()
116  pl.wind(0, 360, -1.2, 1.2)
117
118  -- Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y.
119  pl.col0(1)
120  pl.box("bcnst", 60, 2, "bcnstv", 0.2, 2)
121
122  -- Superimpose a dashed line grid, with 1.5 mm marks and spaces. plstyl
123  -- expects a pointer!!
124  pl.styl(mark1, space1)
125  pl.col0(2)
126  pl.box("g", 30, 0, "g", 0.2, 0)
127  pl.styl(mark0, space0)
128
129  pl.col0(3)
130  pl.lab("Angle (degrees)", "sine", "#frPLplot Example 1 - Sine function")
131
132  for i = 1, 101 do
133    x[i] = 3.6 * (i-1)
134    y[i] = math.sin(x[i]*math.pi/180)
135  end
136
137  pl.col0(4)
138  pl.line(x, y)
139  pl.flush()
140end
141
142
143function plot4()
144  x0 = {}
145  y0 = {}
146  x = {}
147  y = {}
148
149  dtr = math.pi/180
150  for i = 1, 361 do
151    x0[i] = math.cos(dtr*(i-1))
152    y0[i] = math.sin(dtr*(i-1))
153  end
154
155  -- Set up viewport and window, but do not draw box
156  pl.env(-1.3, 1.3, -1.3, 1.3, 1, -2)
157  for i = 1, 10 do
158      for j = 1, 361 do
159        x[j] = 0.1*i*x0[j]
160        y[j] = 0.1*i*y0[j]
161    end
162
163    -- Draw circles for polar grid
164      pl.line(x, y)
165  end
166
167  pl.col0(2)
168  for i = 1, 12 do
169    theta = 30.0 * (i-1)
170    dx = math.cos(dtr * theta)
171    dy = math.sin(dtr * theta)
172
173    -- Draw radial spokes for polar grid
174    pl.join(0, 0, dx, dy)
175
176    -- Write labels for angle
177    -- Slightly off zero to avoid floating point logic flips at 90 and 270 deg.
178    if dx>=-0.00001 then
179      pl.ptex(dx, dy, dx, dy, -0.15, tostring(theta))
180    else
181      pl.ptex(dx, dy, -dx, -dy, 1.15, tostring(theta))
182    end
183  end
184
185  x = {}
186  y = {}
187
188  -- Draw the graph
189  for i = 1, 361 do
190    r = math.sin(dtr * (5*(i-1)))
191    x[i] = x0[i] * r
192    y[i] = y0[i] * r
193  end
194
195  pl.col0(3)
196  pl.line(x, y)
197
198  pl.col0(4)
199  pl.mtex("t", 2, 0.5, 0.5, "#frPLplot Example 3 - r(#gh)=sin 5#gh")
200  pl.flush()
201end
202
203-- Demonstration of contour plotting
204
205XPTS = 35
206YPTS = 46
207XSPA = 2/(XPTS-1)
208YSPA = 2/(YPTS-1)
209
210tr = { XSPA, 0, -1, 0, YSPA, -1 }
211
212function mypltr(x, y)
213  tx = tr[1]*x + tr[2]*y + tr[3]
214  ty = tr[4]*x + tr[5]*y + tr[6]
215
216  return tx, ty
217end
218
219clevel = { -1, -.8, -.6, -.4, -.2, 0, .2, .4, .6, .8, 1 }
220
221function plot5()
222  mark = { 1500 }
223  space = { 1500 }
224
225  -- Set up function arrays
226  z = {}
227  w = {}
228
229  for i = 1, XPTS do
230      xx = (i-1-math.floor(XPTS/2))/math.floor(XPTS/2)
231    z[i] = {}
232    w[i] = {}
233    for j = 1, YPTS do
234      yy = (j-1-math.floor(YPTS/2))/math.floor(YPTS/2)-1
235      z[i][j] = xx * xx - yy * yy
236      w[i][j] = 2 * xx * yy
237    end
238  end
239
240  pl.env(-1, 1, -1, 1, 0, 0)
241  pl.col0(2)
242  pl.cont(z, 1, XPTS, 1, YPTS, clevel, "mypltr")
243  pl.styl(mark, space)
244  pl.col0(3)
245  pl.cont(w, 1, XPTS, 1, YPTS, clevel, "mypltr")
246  pl.col0(1)
247  pl.lab("X Coordinate", "Y Coordinate", "Streamlines of flow")
248  pl.flush()
249end
250
251
252----------------------------------------------------------------------------
253-- main
254--
255-- Plots several simple functions from other example programs.
256--
257-- This version sends the output of the first 4 plots (one page) to two
258-- independent streams.
259----------------------------------------------------------------------------
260
261-- Select either TK or DP driver and use a small window
262-- Using DP results in a crash at the end due to some odd cleanup problems
263-- The geometry strings MUST be in writable memory
264geometry_master = "500x410+100+200"
265geometry_slave = "500x410+650+200"
266
267-- plplot initialization
268-- Parse and process command line arguments
269pl.parseopts(arg, pl.PL_PARSE_FULL)
270
271-- If valid geometry specified on command line, use it for both streams.
272xp0, yp0, xleng0, yleng0, xoff0, yoff0 = pl.gpage()
273valid_geometry = xleng0>0 and yleng0>0
274
275-- Set up first stream
276if valid_geometry==true then
277  pl.spage(xp0, yp0, xleng0, yleng0, xoff0, yoff0)
278else
279  pl.setopt("geometry", geometry_master)
280end
281
282pl.ssub(2, 2)
283pl.init()
284
285driver = pl.gdev()
286fam, num, bmax = pl.gfam()
287
288print("Demo of multiple output streams via the " .. driver .." driver.")
289print("Running with the second stream as slave to the first.\n")
290
291-- Start next stream
292pl.sstrm(1)
293
294if valid_geometry==true then
295  pl.spage(xp0, yp0, xleng0, yleng0, xoff0, yoff0)
296else
297  pl.setopt("geometry", geometry_slave)
298end
299
300-- Turn off pause to make this a slave (must follow master)
301pl.spause(0)
302pl.sdev(driver)
303pl.sfam(fam,num,bmax)
304
305-- Currently number of digits in format number can only be
306--set via the command line option
307pl.setopt("fflen", "2")
308pl.init()
309
310-- Set up the data & plot
311-- Original case
312pl.sstrm(0)
313
314xscale = 6
315yscale = 1
316xoff = 0
317yoff = 0
318plot1()
319
320-- Set up the data & plot
321xscale = 1
322yscale = 1e6
323plot1()
324
325-- Set up the data & plot
326xscale = 1.
327yscale = 1.e-6
328digmax = 2
329pl.syax(digmax, 0)
330plot1()
331
332-- Set up the data & plot
333xscale = 1
334yscale = 0.0014
335yoff = 0.0185
336digmax = 5
337pl.syax(digmax, 0)
338plot1()
339
340-- To slave
341-- The pleop() ensures the eop indicator gets lit.
342pl.sstrm(1)
343plot4()
344pl.eop()
345
346-- Back to master
347pl.sstrm(0)
348plot2()
349plot3()
350
351-- To slave
352pl.sstrm(1)
353plot5()
354pl.eop()
355
356-- Back to master to wait for user to advance
357pl.sstrm(0)
358pl.eop()
359
360-- Call plend to finish off.
361pl.plend()
nanonote-example-files/files/lua-plplot-examples/x15.lua
1--[[ $Id: x15.lua 9533 2009-02-16 22:18:37Z smekal $
2
3    Shade plot demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27XPTS = 35 -- Data points in x
28YPTS = 46 -- Data points in y
29
30z = {}
31
32-- Function prototypes
33
34----------------------------------------------------------------------------
35-- cmap1_init1
36--
37-- Initializes color map 1 in HLS space.
38----------------------------------------------------------------------------
39
40function cmap1_init1()
41  i = { 0, 0,45, 0.55, 1 } -- left boundary, just before center,
42                            -- just after center, right boundary
43  h = { 260, 260, 20, 20 } -- hue -- low: blue-violet, only change as we go over vertex
44                            -- hue -- high: red, keep fixed
45  l = { 0.5, 0, 0, 0.5 } -- lightness -- low, lightness -- center
46                          -- lightness -- center, lightness -- high
47  s = { 1, 1, 1, 1 } -- maximum saturation
48
49  pl.scmap1l(0, i, h, l, s)
50end
51
52
53----------------------------------------------------------------------------
54-- cmap1_init2
55--
56-- Initializes color map 1 in HLS space.
57----------------------------------------------------------------------------
58
59function cmap1_init2()
60  i = { 0, 0.45, 0.55, 1 } -- left boundary, just before center,
61                            -- just after center, right boundary
62  h = { 260, 260, 20, 20 } -- hue -- low: blue-violet, only change as we go over vertex
63                            -- hue -- high: red, keep fixed
64  l = { 0.6, 0, 0, 0.6 } -- lightness -- low, lightness -- center
65                          -- lightness -- center, lightness -- high
66  s = { 1, 0.5, 0.5, 1 } -- saturation -- low, saturation -- center
67                          -- saturation -- center, saturation -- high
68
69  pl.scmap1l(0, i, h, l, s)
70end
71
72
73----------------------------------------------------------------------------
74-- plot1
75--
76-- Illustrates a single shaded region.
77----------------------------------------------------------------------------
78
79function plot1()
80  sh_cmap = 0
81
82  pl.adv(0)
83  pl.vpor(0.1, 0.9, 0.1, 0.9)
84  pl.wind(-1, 1, -1, 1)
85
86  -- Plot using identity transform
87  shade_min = zmin + (zmax-zmin)*0.4
88  shade_max = zmin + (zmax-zmin)*0.6
89  sh_color = 7
90  sh_width = 2
91  min_color = 9
92  max_color = 2
93  min_width = 2
94  max_width = 2
95
96  pl.psty(8)
97  pl.shade(z, -1, 1, -1, 1, shade_min, shade_max, sh_cmap, sh_color, sh_width,
98            min_color, min_width, max_color, max_width, 1)
99
100  pl.col0(1)
101  pl.box("bcnst", 0, 0, "bcnstv", 0, 0)
102  pl.col0(2)
103  pl.lab("distance", "altitude", "Bogon flux")
104end
105
106
107----------------------------------------------------------------------------
108-- plot2
109--
110-- Illustrates multiple adjacent shaded regions, using different fill
111-- patterns for each region.
112----------------------------------------------------------------------------
113
114function plot2()
115  sh_cmap = 0
116  min_color = 0
117  min_width = 0
118  max_color = 0
119  max_width = 0
120
121  inc = { {450}, {-450}, {0}, {900}, {300},
122          {450,-450}, {0, 900}, {0, 450}, {450, -450}, {0, 900} }
123  del = { {2000}, {2000}, {2000}, {2000}, {2000},
124          {2000, 2000}, {2000, 2000}, {2000, 2000}, {4000, 4000}, {4000, 2000} }
125
126  sh_width = 2
127
128  pl.adv(0)
129  pl.vpor(0.1, 0.9, 0.1, 0.9)
130  pl.wind(-1, 1, -1, 1)
131
132  -- Plot using identity transform
133
134  for i = 1, 10 do
135    shade_min = zmin + (zmax - zmin) * (i-1)/10
136    shade_max = zmin + (zmax - zmin) * i/10
137    sh_color = i+5
138    pl.pat(inc[i], del[i])
139
140    pl.shade(z, -1, 1, -1, 1, shade_min, shade_max, sh_cmap, sh_color, sh_width,
141             min_color, min_width, max_color, max_width, 1)
142  end
143
144  pl.col0(1)
145  pl.box("bcnst", 0, 0, "bcnstv", 0, 0)
146  pl.col0(2)
147  pl.lab("distance", "altitude", "Bogon flux")
148end
149
150
151----------------------------------------------------------------------------
152-- plot3
153--
154-- Illustrates shaded regions in 3d, using a different fill pattern for
155-- each region.
156----------------------------------------------------------------------------
157
158function plot3()
159  xx = { {-1, 1, 1, -1, -1}, {-1, 1, 1, -1, -1} }
160  yy = { {1, 1, 0, 0, 1}, {-1, -1, 0, 0, -1} }
161  zz = { {0, 0, 1, 1, 0}, {0, 0, 1, 1, 0} }
162
163  pl.adv(0)
164  pl.vpor(0.1, 0.9, 0.1, 0.9)
165  pl.wind(-1, 1, -1, 1.)
166  pl.w3d(1, 1, 1, -1, 1, -1, 1, 0, 1.5, 30, -40)
167
168  -- Plot using identity transform
169  pl.col0(1)
170  pl.box3("bntu", "X", 0, 0, "bntu", "Y", 0, 0, "bcdfntu", "Z", 0.5, 0)
171  pl.col0(2)
172  pl.lab("","","3-d polygon filling")
173
174  pl.col0(3)
175  pl.psty(1)
176  pl.line3(xx[1], yy[1], zz[1])
177  pl.fill3(xx[1], yy[1], zz[1])
178  pl.psty(2)
179  pl.line3(xx[2], yy[2], zz[2])
180  pl.fill3(xx[2], yy[2], zz[2])
181end
182
183
184----------------------------------------------------------------------------
185-- f2mnmx
186--
187-- Returns min & max of input 2d array.
188----------------------------------------------------------------------------
189
190function f2mnmx(f, nx, ny)
191    fmax = f[1][1]
192    fmin = fmax
193
194    for i=1, nx do
195        for j=1, ny do
196        fmax = math.max(fmax, f[i][j])
197        fmin = math.min(fmin, f[i][j])
198        end
199    end
200
201    return fmin, fmax
202end
203
204----------------------------------------------------------------------------
205-- main
206--
207-- Does a variety of shade plots.
208----------------------------------------------------------------------------
209
210-- Parse and process command line arguments
211pl.parseopts(arg, pl.PL_PARSE_FULL)
212
213-- Set up color map 1
214cmap1_init2()
215
216-- Initialize plplot
217pl.init()
218
219-- Set up data array
220for i=1, XPTS do
221    xx = ((i-1) - math.floor(XPTS/2))/math.floor(XPTS/2)
222  z[i] = {}
223    for j = 1, YPTS do
224    yy = ((j-1) - math.floor(YPTS/2))/math.floor(YPTS/2) - 1
225    z[i][j] = xx^2 - yy^2 + (xx - yy)/(xx^2+yy^2 + 0.1)
226    end
227end
228zmin, zmax = f2mnmx(z, XPTS, YPTS)
229
230plot1()
231plot2()
232plot3()
233
234pl.plend()
nanonote-example-files/files/lua-plplot-examples/x16.lua
1--[[ $Id: x16.lua 10304 2009-08-20 09:05:43Z andrewross $
2
3    plshade demo, using color fill.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27-- Fundamental settings. See notes[] for more info.
28ns = 20 -- Default number of shade levels
29nx = 35 -- Default number of data points in x
30ny = 46 -- Default number of data points in y
31exclude = 0 -- By default do not plot a page illustrating
32              -- exclusion. API is probably going to change
33              -- anyway, and cannot be reproduced by any
34                      -- front end other than the C one.
35
36-- polar plot data
37PERIMETERPTS = 100
38
39-- Transformation function
40tr = {}
41
42function mypltr(x, y)
43    tx = tr[1] * x + tr[2] * y + tr[3]
44    ty = tr[4] * x + tr[5] * y + tr[6]
45
46    return tx, ty
47end
48
49----------------------------------------------------------------------------
50-- f2mnmx
51--
52-- Returns min & max of input 2d array.
53----------------------------------------------------------------------------
54function f2mnmx(f, nx, ny)
55  fmax = f[1][1]
56  fmin = fmax
57
58  for i = 1, nx do
59    for j = 1, ny do
60      fmax = math.max(fmax, f[i][j])
61      fmin = math.min(fmin, f[i][j])
62    end
63  end
64
65  return fmin, fmax
66end
67
68
69function zdefined(x, y)
70  z = math.sqrt(x^2 + y^2)
71
72  return z<0.4 or z>0.6
73end
74
75
76----------------------------------------------------------------------------
77-- main
78--
79-- Does several shade plots using different coordinate mappings.
80----------------------------------------------------------------------------
81
82px = {}
83py = {}
84
85fill_width = 2
86cont_color = 0
87cont_width = 0
88
89-- Parse and process command line arguments
90pl.parseopts(arg, pl.PL_PARSE_FULL)
91
92-- Load colour palettes
93pl.spal0("cmap0_black_on_white.pal");
94pl.spal1("cmap1_gray.pal",1);
95
96-- Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
97pl.scmap0n(3)
98
99-- Initialize plplot
100pl.init()
101
102-- Set up transformation function
103tr = { 2/(nx-1), 0, -1, 0, 2/(ny-1), -1 }
104
105-- Allocate data structures
106clevel = {}
107shedge = {}
108z = {}
109w = {}
110
111-- Set up data array
112for i = 1, nx do
113    x = (i-1 - math.floor(nx/2))/math.floor(nx/2)
114  z[i] = {}
115  w[i] = {}
116    for j = 1, ny do
117    y = (j-1 - math.floor(ny/2))/math.floor(ny/2)-1
118    z[i][j] = -math.sin(7*x) * math.cos(7*y) + x^2 - y^2
119    w[i][j] = -math.cos(7*x) * math.sin(7*y) + 2*x*y
120    end
121end
122
123zmin, zmax = f2mnmx(z, nx, ny)
124for i = 1, ns do
125    clevel[i] = zmin + (zmax-zmin)*(i-0.5)/ns
126end
127
128for i = 1, ns+1 do
129    shedge[i] = zmin + (zmax-zmin)*(i-1)/ns
130end
131
132-- Set up coordinate grids
133cgrid1 = {}
134cgrid1["xg"] = {}
135cgrid1["yg"] = {}
136cgrid1["nx"] = nx
137cgrid1["ny"] = ny
138
139cgrid2 = {}
140cgrid2["xg"] = {}
141cgrid2["yg"] = {}
142cgrid2["nx"] = nx
143cgrid2["ny"] = ny
144
145for i = 1, nx do
146  cgrid2["xg"][i] = {}
147  cgrid2["yg"][i] = {}
148    for j = 1, ny do
149    x, y = mypltr(i-1, j-1)
150
151    argx = x*math.pi/2
152    argy = y*math.pi/2
153    distort = 0.4
154
155    cgrid1["xg"][i] = x + distort * math.cos(argx)
156    cgrid1["yg"][j] = y - distort * math.cos(argy)
157
158    cgrid2["xg"][i][j] = x + distort * math.cos(argx) * math.cos(argy)
159    cgrid2["yg"][i][j] = y - distort * math.cos(argx) * math.cos(argy)
160  end
161end
162
163-- Plot using identity transform
164pl.adv(0)
165pl.vpor(0.1, 0.9, 0.1, 0.9)
166pl.wind(-1, 1, -1, 1)
167
168pl.psty(0)
169
170pl.shades(z, -1, 1, -1, 1, shedge, fill_width, cont_color, cont_width, 1)
171
172pl.col0(1)
173pl.box("bcnst", 0, 0, "bcnstv", 0, 0)
174pl.col0(2)
175
176--pl.cont(w, 1, nx, 1, ny, clevel, mypltr, {})
177pl.lab("distance", "altitude", "Bogon density")
178
179-- Plot using 1d coordinate transform
180
181-- Load colour palettes
182pl.spal0("cmap0_black_on_white.pal");
183pl.spal1("cmap1_blue_yellow.pal",1);
184
185-- Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
186pl.scmap0n(3);
187
188pl.adv(0)
189pl.vpor(0.1, 0.9, 0.1, 0.9)
190pl.wind(-1, 1, -1, 1)
191
192pl.psty(0)
193
194pl.shades(z, -1, 1, -1, 1, shedge, fill_width, cont_color, cont_width, 1, "pltr1", cgrid1)
195
196pl.col0(1)
197pl.box("bcnst", 0, 0, "bcnstv", 0, 0)
198pl.col0(2)
199pl.lab("distance", "altitude", "Bogon density")
200
201-- Plot using 2d coordinate transform
202
203-- Load colour palettes
204pl.spal0("cmap0_black_on_white.pal");
205pl.spal1("cmap1_blue_red.pal",1);
206
207-- Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
208pl.scmap0n(3);
209
210pl.adv(0)
211pl.vpor(0.1, 0.9, 0.1, 0.9)
212pl.wind(-1, 1, -1, 1)
213
214pl.psty(0)
215
216pl.shades(z, -1, 1, -1, 1, shedge, fill_width, cont_color, cont_width, 0, "pltr2", cgrid2)
217
218pl.col0(1)
219pl.box("bcnst", 0, 0, "bcnstv", 0, 0)
220pl.col0(2)
221pl.cont(w, 1, nx, 1, ny, clevel, "pltr2", cgrid2)
222
223pl.lab("distance", "altitude", "Bogon density, with streamlines")
224
225-- Plot using 2d coordinate transform
226
227-- Load colour palettes
228pl.spal0("");
229pl.spal1("",1);
230
231-- Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
232pl.scmap0n(3);
233
234pl.adv(0)
235pl.vpor(0.1, 0.9, 0.1, 0.9)
236pl.wind(-1, 1, -1, 1)
237
238pl.psty(0)
239
240pl.shades(z, -1, 1, -1, 1, shedge, fill_width, 2, 3, 0, "pltr2", cgrid2)
241
242pl.col0(1)
243pl.box("bcnst", 0, 0, "bcnstv", 0, 0)
244pl.col0(2)
245
246pl.lab("distance", "altitude", "Bogon density")
247
248-- Note this exclusion API will probably change.
249
250-- Plot using 2d coordinate transform and exclusion
251if exclude~=0 then
252
253    -- Load colour palettes
254  pl.spal0("cmap0_black_on_white.pal");
255  pl.spal1("cmap1_gray.pal",1);
256
257    -- Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
258  pl.scmap0n(3);
259
260  pl.adv(0)
261  pl.vpor(0.1, 0.9, 0.1, 0.9)
262  pl.wind(-1, 1, -1, 1)
263
264  plpsty(0)
265
266  pl.shades(z, zdefined, -1, 1, -1, 1, shedge, fill_width, cont_color, cont_width,
267            0, "pltr2", cgrid2)
268
269  pl.col0(1)
270  pl.box("bcnst", 0, 0, "bcnstv", 0, 0)
271
272  pl.lab("distance", "altitude", "Bogon density with exclusion")
273end
274
275-- Example with polar coordinates.
276
277-- Load colour palettes
278pl.spal0("cmap0_black_on_white.pal");
279pl.spal1("cmap1_gray.pal",1);
280
281-- Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
282pl.scmap0n(3);
283
284pl.adv(0)
285pl.vpor(.1, .9, .1, .9)
286pl.wind(-1, 1, -1, 1)
287
288pl.psty(0)
289
290-- Build new coordinate matrices.
291for i = 1, nx do
292  r = (i-1)/(nx-1)
293    for j = 1, ny do
294       t = 2*math.pi/(ny-1)*(j-1)
295       cgrid2["xg"][i][j] = r*math.cos(t)
296       cgrid2["yg"][i][j] = r*math.sin(t)
297       z[i][j] = math.exp(-r^2)*math.cos(5*math.pi*r)*math.cos(5*t)
298    end
299end
300
301-- Need a new shedge to go along with the new data set.
302zmin, zmax = f2mnmx(z, nx, ny)
303
304for i = 1, ns+1 do
305    shedge[i] = zmin + (zmax-zmin)*(i-1)/ns
306end
307
308-- Now we can shade the interior region.
309pl.shades(z, -1, 1, -1, 1, shedge, fill_width, cont_color, cont_width, 0, "pltr2", cgrid2)
310
311-- Now we can draw the perimeter. (If do before, shade stuff may overlap.)
312for i = 1, PERIMETERPTS do
313   t = 2*math.pi/(PERIMETERPTS-1)*(i-1)
314   px[i] = math.cos(t)
315   py[i] = math.sin(t)
316end
317pl.col0(1)
318pl.line(px, py)
319
320-- And label the plot.
321pl.col0(2)
322pl.lab( "", "", "Tokamak Bogon Instability" )
323
324pl.plend()
nanonote-example-files/files/lua-plplot-examples/x17.lua
1--[[ $Id: x17.lua 9526 2009-02-13 22:06:13Z smekal $
2
3    Plots a simple stripchart with four pens.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24
25-- initialise Lua bindings for PLplot examples.
26dofile("plplot_examples.lua")
27
28
29--------------------------------------------------------------------------
30-- main
31--------------------------------------------------------------------------
32
33nsteps = 1000
34colline = {}
35legline = {}
36
37-- plplot initialization
38-- Parse and process command line arguments
39pl.parseopts(arg, pl.PL_PARSE_FULL)
40
41-- User sets up plot completely except for window and data
42-- Eventually settings in place when strip chart is created will be
43-- remembered so that multiple strip charts can be used simultaneously.
44
45-- Specify some reasonable defaults for ymin and ymax
46-- The plot will grow automatically if needed (but not shrink)
47ymin = -0.1
48ymax = 0.1
49
50-- Specify initial tmin and tmax -- this determines length of window.
51-- Also specify maximum jump in t
52-- This can accomodate adaptive timesteps
53tmin = 0
54tmax = 10
55tjump = 0.3 -- percentage of plot to jump
56
57-- Axes options same as plbox.
58-- Only automatic tick generation and label placement allowed
59-- Eventually I'll make this fancier
60colbox = 1
61collab = 3
62styline = { 2, 3, 4, 5 } -- line style
63colline = { 2, 3, 4, 5 } -- pens color
64
65legline= { "sum", "sin", "sin*noi", "sin+noi" } -- pens legend
66
67xlab = 0 -- legend position
68ylab = 0.25
69
70autoy = 1 -- autoscale y
71acc = 1 -- don't scrip, accumulate
72
73-- Initialize plplot
74pl.init()
75
76pl.adv(0)
77pl.vsta()
78
79id1 = pl.stripc("bcnst", "bcnstv",
80   tmin, tmax, tjump, ymin, ymax,
81   xlab, ylab,
82   autoy, acc,
83   colbox, collab,
84   colline, styline, legline,
85   "t", "", "Strip chart demo")
86
87autoy = 0 -- autoscale y
88acc = 1 -- accumulate
89
90-- This is to represent a loop over time
91-- Let's try a random walk process
92
93y1 = 0
94y2 = 0
95y3 = 0
96y4 = 0
97dt = 0.1
98
99for n = 0, nsteps-1 do
100    for i = 0, 200000 do end
101    t = n * dt
102    noise = pl.randd() - 0.5
103    y1 = y1 + noise
104    y2 = math.sin(t*math.pi/18)
105    y3 = y2 * noise
106    y4 = y2 + noise/3
107
108  -- There is no need for all pens to have the same number of
109  -- points or beeing equally time spaced.
110    if math.mod(n, 2)~=0 then pl.stripa(id1, 0, t, y1) end
111    if math.mod(n, 3)~=0 then pl.stripa(id1, 1, t, y2) end
112    if math.mod(n, 4)~=0 then pl.stripa(id1, 2, t, y3) end
113    if math.mod(n, 5)~=0 then pl.stripa(id1, 3, t, y4) end
114end
115
116-- Destroy strip chart and it's memory
117pl.stripd(id1)
118pl.plend()
nanonote-example-files/files/lua-plplot-examples/x18.lua
1--[[ $Id: x18.lua 9526 2009-02-13 22:06:13Z smekal $
2
3    3-d line and point plot demo. Adapted from x08c.c.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27function test_poly(k)
28  draw= { { 1, 1, 1, 1 },
29          { 1, 0, 1, 0 },
30          { 0, 1, 0, 1 },
31          { 1, 1, 0, 0 } }
32
33  x = {}
34  y = {}
35  z = {}
36
37  pl.adv(0)
38  pl.vpor(0, 1, 0, 0.9)
39  pl.wind(-1, 1, -0.9, 1.1)
40  pl.col0(1)
41  pl.w3d(1, 1, 1, -1, 1, -1, 1, -1, 1, alt[k], az[k])
42  pl.box3("bnstu", "x axis", 0, 0,
43          "bnstu", "y axis", 0, 0,
44          "bcdmnstuv", "z axis", 0, 0)
45
46  pl.col0(2)
47
48  -- x = r sin(phi) cos(theta)
49  -- y = r sin(phi) sin(theta)
50  -- z = r cos(phi)
51  -- r = 1 :=)
52
53  for i=0, 19 do
54    for j=0, 19 do
55        x[1] = math.sin( math.pi*j/20.1 ) * math.cos( 2*math.pi*i/20 )
56        y[1] = math.sin( math.pi*j/20.1 ) * math.sin( 2*math.pi*i/20 )
57        z[1] = math.cos( math.pi*j/20.1 )
58
59        x[2] = math.sin( math.pi*(j+1)/20.1 ) * math.cos( 2*math.pi*i/20 )
60        y[2] = math.sin( math.pi*(j+1)/20.1 ) * math.sin( 2*math.pi*i/20 )
61        z[2] = math.cos( math.pi*(j+1)/20.1 )
62
63        x[3] = math.sin( math.pi*(j+1)/20.1 ) * math.cos( 2*math.pi*(i+1)/20 )
64        y[3] = math.sin( math.pi*(j+1)/20.1 ) * math.sin( 2*math.pi*(i+1)/20 )
65        z[3] = math.cos( math.pi*(j+1)/20.1 )
66
67        x[4] = math.sin( math.pi*j/20.1 ) * math.cos( 2*math.pi*(i+1)/20 )
68        y[4] = math.sin( math.pi*j/20.1 ) * math.sin( 2*math.pi*(i+1)/20 )
69        z[4] = math.cos( math.pi*j/20.1 )
70
71        x[5] = math.sin( math.pi*j/20.1 ) * math.cos( 2*math.pi*i/20 )
72        y[5] = math.sin( math.pi*j/20.1 ) * math.sin( 2*math.pi*i/20 )
73        z[5] = math.cos( math.pi*j/20.1 )
74
75        pl.poly3( x, y, z, draw[k], 1 )
76    end
77  end
78
79  pl.col0(3)
80  pl.mtex("t", 1, 0.5, 0.5, "unit radius sphere" )
81end
82
83
84----------------------------------------------------------------------------
85-- main
86--
87-- Does a series of 3-d plots for a given data set, with different
88-- viewing options in each plot.
89----------------------------------------------------------------------------
90
91NPTS = 1000
92opt = { 1, 0, 1, 0 }
93alt = { 20, 35, 50, 65 }
94az = { 30, 40, 50, 60 }
95
96
97-- Parse and process command line arguments
98pl.parseopts(arg, pl.PL_PARSE_FULL)
99
100-- Initialize plplot
101pl.init()
102
103for k=1, 4 do
104    test_poly(k)
105end
106
107x = {}
108y = {}
109z = {}
110
111-- From the mind of a sick and twisted physicist...
112for i=1, NPTS do
113  z[i] = -1 + 2*(i-1)/NPTS
114
115  -- Pick one ...
116  -- r = 1 - (i-1) / NPTS
117  r = z[i]
118
119  x[i] = r * math.cos( 12*math.pi*(i-1)/NPTS )
120  y[i] = r * math.sin( 12*math.pi*(i-1)/NPTS )
121end
122
123for k=1, 4 do
124    pl.adv(0)
125    pl.vpor(0, 1, 0, 0.9)
126    pl.wind(-1, 1, -0.9, 1.1)
127    pl.col0(1)
128    pl.w3d(1, 1, 1, -1, 1, -1, 1, -1, 1, alt[k], az[k])
129    pl.box3("bnstu", "x axis", 0, 0,
130            "bnstu", "y axis", 0, 0,
131            "bcdmnstuv", "z axis", 0, 0)
132
133    pl.col0(2)
134
135    if opt[k]~=0 then
136    pl.line3( x, y, z )
137    else
138    pl.poin3( x, y, z, 1 )
139  end
140
141    pl.col0(3)
142    pl.mtex("t", 1.0, 0.5, 0.5, "#frPLplot Example 18 - Alt=" .. alt[k] .. ", Az=" .. az[k])
143end
144
145pl.plend()
nanonote-example-files/files/lua-plplot-examples/x19.lua
1--[[ $Id: x19.lua 10293 2009-08-19 07:57:43Z smekal $
2
3    Illustrates backdrop plotting of world, US maps.
4    Contributed by Wesley Ebisuzaki.
5
6  Copyright (C) 2008 Werner Smekal
7
8  This file is part of PLplot.
9
10  PLplot is free software you can redistribute it and/or modify
11  it under the terms of the GNU General Library Public License as published
12  by the Free Software Foundation either version 2 of the License, or
13  (at your option) any later version.
14
15  PLplot is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Library General Public License for more details.
19
20  You should have received a copy of the GNU Library General Public License
21  along with PLplot if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23--]]
24
25-- initialise Lua bindings for PLplot examples.
26dofile("plplot_examples.lua")
27
28--------------------------------------------------------------------------
29-- mapform19
30--
31-- Defines specific coordinate transformation for example 19.
32-- Not to be confused with mapform in src/plmap.c.
33-- x[], y[] are the coordinates to be plotted.
34--------------------------------------------------------------------------
35
36function mapform19(n, x, y)
37  for i = 1, n do
38    radius = 90 - y[i]
39    xp = radius * math.cos(x[i] * math.pi / 180)
40    yp = radius * math.sin(x[i] * math.pi / 180)
41    x[i] = xp
42    y[i] = yp
43  end
44
45  return x, y
46end
47
48-- "Normalize" longitude values so that they always fall between
49-- -180.0 and 180.0
50function normalize_longitude(lon)
51    if lon>=-180 and lon<=180 then
52        return lon;
53    else
54            times = math.floor((math.abs(lon)+180)/360)
55            if lon<0 then
56                return lon+360*times
57            else
58                return lon-360*times
59            end
60    end
61end
62
63-- A custom axis labeling function for longitudes and latitudes.
64function geolocation_labeler(axis, value)
65    if axis==pl.PL_Y_AXIS then
66        label_val = value
67        if label_val>0 then
68            direction_label = " N"
69        else
70            if label_val<0 then
71                direction_label = " S"
72            else
73                direction_label = "Eq"
74            end
75        end
76    else
77        if axis==pl.PL_X_AXIS then
78            label_val = normalize_longitude(value);
79            if label_val>0 then
80                direction_label = " E"
81            else
82                if label_val<0 then
83                    direction_label = " W"
84                else
85                    direction_label = ""
86                end
87            end
88        end
89    end
90
91    if axis==pl.PL_Y_AXIS and value==0 then
92        -- A special case for the equator
93        label = direction_label
94    else
95        label = math.abs(label_val) .. direction_label
96    end
97
98    return label
99end
100
101--------------------------------------------------------------------------
102-- main
103--
104-- Shows two views of the world map.
105--------------------------------------------------------------------------
106
107-- Parse and process command line arguments
108
109pl.parseopts(arg, pl.PL_PARSE_FULL)
110
111-- Longitude (x) and latitude (y)
112
113miny = -70
114maxy = 80
115
116pl.init()
117
118-- Cartesian plots
119-- Most of world
120
121minx = 190
122maxx = 190+360
123
124-- Setup a custom latitude and longitude-based scaling function.
125pl.slabelfunc("geolocation_labeler");
126
127pl.col0(1)
128pl.env(minx, maxx, miny, maxy, 1, 70)
129pl.map(nil, "usaglobe", minx, maxx, miny, maxy)
130
131-- The Americas
132
133minx = 190
134maxx = 340
135
136pl.col0(1)
137pl.env(minx, maxx, miny, maxy, 1, 70)
138pl.map(nil, "usaglobe", minx, maxx, miny, maxy)
139
140-- Clear the labeling function
141pl.slabelfunc(nil);
142
143-- Polar, Northern hemisphere
144
145minx = 0
146maxx = 360
147
148pl.env(-75., 75., -75., 75., 1, -1)
149pl.map("mapform19", "globe", minx, maxx, miny, maxy)
150
151pl.lsty(2)
152pl.meridians("mapform19", 10, 10, 0, 360, -10, 80)
153pl.plend()
nanonote-example-files/files/lua-plplot-examples/x20.lua
1--[[ $Id: x20.lua 9535 2009-02-17 10:14:04Z smekal $
2
3    plimage demo
4--]]
5
6-- initialise Lua bindings for PLplot examples.
7dofile("plplot_examples.lua")
8
9XDIM = 260
10YDIM = 220
11
12dbg = 0
13nosombrero = 0
14nointeractive = 0
15f_name=""
16
17
18-- Transformation function
19function mypltr(x, y)
20  local x0 = (stretch["xmin"] + stretch["xmax"])*0.5
21  local y0 = (stretch["ymin"] + stretch["ymax"])*0.5
22  local dy = (stretch["ymax"]-stretch["ymin"])*0.5
23  local tx = x0 + (x0-x)*(1 - stretch["stretch"]*math.cos((y-y0)/dy*math.pi*0.5))
24  local ty = y
25
26  return tx, ty
27end
28
29
30-- read image from file in binary ppm format
31function read_img(fname)
32  -- naive grayscale binary ppm reading. If you know how to, improve it
33  local fp = io.open(fname, "rb")
34  if fp==nil then
35    return 1
36  end
37
38  -- version
39  local ver = fp:read("*line")
40
41  if ver~="P5" then -- I only understand this!
42    fp:close()
43    return 1
44  end
45
46  while fp:read(1)=="#" do
47    local com = fp:read("*line")
48    if com==nil then
49      fp:close()
50      return 1
51    end
52  end
53  fp:seek("cur", -1)
54
55  local w, h, num_col = fp:read("*number", "*number", "*number")
56  if w==nil or h==nil or num_col==nil then -- width, height, num colors
57    fp:close()
58    return 1
59  end
60
61  -- read the rest of the line (only EOL)
62  fp:read("*line")
63
64  local img = fp:read(w*h)
65  fp:close()
66  if string.len(img)~=(w*h) then
67    return 1
68  end
69
70  local imf = {}
71
72  for i = 1, w do
73    imf[i] = {}
74    for j = 1, h do
75      imf[i][j] = string.byte(img, (h-j)*w+i) -- flip image up-down
76    end
77  end
78
79  return 0, imf, w, h, num_col
80end
81
82
83-- save plot
84function save_plot(fname)
85  local cur_strm = pl.gstrm() -- get current stream
86  local new_strm = pl.mkstrm() -- create a new one
87
88  pl.sdev("psc") -- new device type. Use a known existing driver
89  pl.sfnam(fname) -- file name
90
91  pl.cpstrm(cur_strm, 0) -- copy old stream parameters to new stream
92  pl.replot() -- do the save
93  pl.end1() -- close new device
94
95  pl.sstrm(cur_strm) -- and return to previous one
96end
97
98
99-- get selection square interactively
100function get_clip(xi, xe, yi, ye)
101  return 0, xi, xe, yi, ye
102end
103
104
105-- set gray colormap
106function gray_cmap(num_col)
107  local r = { 0, 1 }
108  local g = { 0, 1 }
109  local b = { 0, 1 }
110  local pos = { 0, 1 }
111
112  pl.scmap1n(num_col)
113  pl.scmap1l(1, pos, r, g, b)
114end
115
116
117x = {}
118y = {}
119z = {}
120r = {}
121img_f = {}
122cgrid2 = {}
123
124
125-- Bugs in plimage():
126-- + at high magnifications, the left and right edge are ragged, try
127-- ./x20c -dev xwin -wplt 0.3,0.3,0.6,0.6 -ori 0.5
128
129-- Bugs in x20c.c:
130-- + if the window is resized after a selection is made on "lena", when
131  --making a new selection the old one will re-appear.
132
133
134-- Parse and process command line arguments
135pl.parseopts(arg, pl.PL_PARSE_FULL)
136
137-- Initialize plplot
138pl.init()
139
140z={}
141
142-- view image border pixels
143if dbg~=0 then
144  pl.env(1, XDIM, 1, YDIM, 1, 1) -- no plot box
145
146  -- build a one pixel square border, for diagnostics
147  for i = 1, XDIM do
148    z[i] = {}
149    z[i][1] = 1 -- left
150    z[i][YDIM] = 1 -- right
151  end
152
153  for i = 1, YDIM do
154    z[1][i] = 1 -- top
155    z[XDIM][i] = 1 -- botton
156  end
157
158  pl.lab("...around a blue square."," ","A red border should appear...")
159
160  pl.image(z, 1, XDIM, 1, YDIM, 0, 0, 1, XDIM, 1, YDIM)
161end
162
163-- sombrero-like demo
164if nosombrero==0 then
165  r = {}
166  pl.col0(2) -- draw a yellow plot box, useful for diagnostics! :(
167  pl.env(0, 2*math.pi, 0, 3*math.pi, 1, -1)
168
169  for i = 1, XDIM do
170    x[i] = (i-1)*2*math.pi/(XDIM-1)
171  end
172  for i = 1, YDIM do
173    y[i] = (i-1)*3*math.pi/(YDIM-1)
174  end
175
176  for i = 1, XDIM do
177    r[i] = {}
178    z[i] = {}
179    for j=1, YDIM do
180      r[i][j] = math.sqrt(x[i]^2+y[j]^2)+1e-3
181      z[i][j] = math.sin(r[i][j])/r[i][j]
182    end
183  end
184
185  pl.lab("No, an amplitude clipped \"sombrero\"", "", "Saturn?")
186  pl.ptex(2, 2, 3, 4, 0, "Transparent image")
187  pl.image(z, 0, 2*math.pi, 0, 3*math.pi, 0.05, 1, 0, 2*math.pi, 0, 3*math.pi)
188
189  -- save the plot
190  if f_name~="" then
191    save_plot(f_name)
192  end
193end
194
195-- read Lena image
196-- Note we try two different locations to cover the case where this
197-- examples is being run from the test_c.sh script
198status, img_f, width, height, num_col = read_img("lena.pgm")
199if status~=0 then
200  status, img_f, width, height, num_col = read_img("../lena.pgm")
201  if status~=0 then
202    pl.abort("No such file")
203    pl.plend()
204    os.exit()
205  end
206end
207
208-- set gray colormap
209gray_cmap(num_col)
210
211-- display Lena
212pl.env(1, width, 1, height, 1, -1)
213
214if nointeractive==0 then
215  pl.lab("Set and drag Button 1 to (re)set selection, Button 2 to finish."," ","Lena...")
216else
217  pl.lab(""," ","Lena...")
218end
219
220pl.image(img_f, 1, width, 1, height, 0, 0, 1, width, 1, height)
221
222-- selection/expansion demo
223if nointeractive==0 then
224  xi = 200
225  xe = 330
226  yi = 280
227  ye = 220
228
229  status, xi, xe, yi, ye = get_clip(xi, xe, yi, ye)
230  if status~=0 then -- get selection rectangle
231    pl.plend()
232    os.exit()
233  end
234
235  pl.spause(0)
236  pl.adv(0)
237
238  -- display selection only
239  pl.image(img_f, 1, width, 1, height, 0, 0, xi, xe, ye, yi)
240
241  pl.spause(1)
242
243  -- zoom in selection
244  pl.env(xi, xe, ye, yi, 1, -1)
245  pl.image(img_f, 1, width, 1, height, 0, 0, xi, xe, ye, yi)
246end
247
248-- Base the dynamic range on the image contents.
249img_max, img_min = pl.MinMax2dGrid(img_f)
250
251-- Draw a saturated version of the original image. Only use the middle 50%
252-- of the image's full dynamic range.
253pl.col0(2)
254pl.env(0, width, 0, height, 1, -1)
255pl.lab("", "", "Reduced dynamic range image example")
256pl.imagefr(img_f, 0, width, 0, height, 0, 0, img_min + img_max*0.25, img_max - img_max*0.25)
257
258-- Draw a distorted version of the original image, showing its full dynamic range.
259pl.env(0, width, 0, height, 1, -1)
260pl.lab("", "", "Distorted image example")
261
262stretch = {}
263stretch["xmin"] = 0
264stretch["xmax"] = width
265stretch["ymin"] = 0
266stretch["ymax"] = height
267stretch["stretch"] = 0.5
268
269-- In C / C++ the following would work, with plimagefr directly calling
270-- mypltr. For compatibilty with other language bindings the same effect
271-- can be achieved by generating the transformed grid first and then
272-- using pltr2.
273-- pl.imagefr(img_f, width, height, 0., width, 0., height, 0., 0., img_min, img_max, mypltr, (PLPointer) &stretch)
274
275cgrid2 = {}
276cgrid2["xg"] = {}
277cgrid2["yg"] = {}
278cgrid2["nx"] = width+1
279cgrid2["ny"] = height+1
280
281for i = 1, width+1 do
282  cgrid2["xg"][i] = {}
283  cgrid2["yg"][i] = {}
284  for j = 1, height+1 do
285    xx, yy = mypltr(i, j)
286    cgrid2["xg"][i][j] = xx
287    cgrid2["yg"][i][j] = yy
288  end
289end
290
291--pl.imagefr(img_f, 0, width, 0, height, 0, 0, img_min, img_max, "pltr2", cgrid2)
292pl.imagefr(img_f, 0, width, 0, height, 0, 0, img_min, img_max, "mypltr")
293
294pl.plend()
nanonote-example-files/files/lua-plplot-examples/x21.lua
1--[[ $Id: x21.lua 9533 2009-02-16 22:18:37Z smekal $
2    Grid data demo
3
4   Copyright (C) 200 Werner Smekal
5
6   This file is part of PLplot.
7
8   PLplot is free software you can redistribute it and/or modify
9   it under the terms of the GNU General Library Public License as published
10   by the Free Software Foundation either version 2 of the License, or
11   (at your option) any later version.
12
13   PLplot is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16   GNU Library General Public License for more details.
17
18   You should have received a copy of the GNU Library General Public License
19   along with PLplot if not, write to the Free Software
20   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21--]]
22
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27-- bitwise or operator from http://lua-users.org/wiki/BaseSixtyFour
28-- (c) 2006-2008 by Alex Kloss
29-- licensed under the terms of the LGPL2
30
31-- return single bit (for OR)
32function bit(x,b)
33    return (math.mod(x, 2^b) - math.mod(x,2^(b-1)) > 0)
34end
35
36-- logic OR for number values
37function lor(x,y)
38    result = 0
39    for p=1,8 do result = result + (((bit(x,p) or bit(y,p)) == true) and 2^(p-1) or 0) end
40    return result
41end
42
43-- Options data structure definition.
44pts = 500
45xp = 25
46yp = 20
47nl = 16
48knn_order = 20
49threshold = 1.001
50wmin = -1e3
51randn = 0
52rosen = 0
53
54
55function cmap1_init()
56  i = { 0, 1 } -- left and right boundary
57
58  h = { 240, 0 } -- blue -> green -> yellow -> red
59  l = { 0.6, 0.6 }
60  s = { 0.8, 0.8 }
61
62  pl.scmap1n(256)
63  pl.scmap1l(0, i, h, l, s)
64end
65
66
67function create_grid(px, py)
68  local x = {}
69  local y = {}
70
71  for i = 1, px do
72    x[i] = xm + (xM-xm)*(i-1)/(px-1)
73  end
74
75  for i = 1, py do
76    y[i] = ym + (yM-ym)*(i-1)/(py-1)
77  end
78
79  return x, y
80end
81
82
83function create_data(pts)
84  local x = {}
85  local y = {}
86  local z = {}
87
88  for i = 1, pts do
89    xt = (xM-xm)*pl.randd()
90    yt = (yM-ym)*pl.randd()
91    if randn==0 then
92      x[i] = xt + xm
93      y[i] = yt + ym
94    else -- std=1, meaning that many points are outside the plot range
95      x[i] = math.sqrt(-2*math.log(xt)) * math.cos(2*math.pi*yt) + xm
96      y[i] = math.sqrt(-2*math.log(xt)) * math.sin(2*math.pi*yt) + ym
97    end
98    if rosen==0 then
99      r = math.sqrt(x[i]^2 + y[i]^2)
100      z[i] = math.exp(-r^2) * math.cos(2*math.pi*r)
101    else
102      z[i] = math.log((1-x[i])^2 + 100*(y[i] - x[i]^2)^2)
103    end
104  end
105
106  return x, y, z
107end
108
109
110title = { "Cubic Spline Approximation",
111          "Delaunay Linear Interpolation",
112          "Natural Neighbors Interpolation",
113          "KNN Inv. Distance Weighted",
114          "3NN Linear Interpolation",
115          "4NN Around Inv. Dist. Weighted" }
116
117
118
119xm = -0.2
120ym = -0.2
121xM = 0.6
122yM = 0.6
123
124pl.parseopts(arg, pl.PL_PARSE_FULL)
125
126opt = { 0, 0, wmin, knn_order, threshold, 0 }
127
128-- Initialize plplot
129pl.init()
130
131-- Initialise random number generator
132pl.seed(5489)
133
134x, y, z = create_data(pts) -- the sampled data
135zmin = z[1]
136zmax = z[1]
137for i=2, pts do
138  if z[i]>zmax then zmax = z[i] end
139  if z[i]<zmin then zmin = z[i] end
140end
141
142xg, yg = create_grid(xp, yp) -- grid the data at
143clev = {}
144
145pl.col0(1)
146pl.env(xm, xM, ym, yM, 2, 0)
147pl.col0(15)
148pl.lab("X", "Y", "The original data sampling")
149pl.col0(2)
150pl.poin(x, y, 5)
151pl.adv(0)
152
153pl.ssub(3, 2)
154
155for k = 1, 2 do
156  pl.adv(0)
157  for alg=1, 6 do
158    zg = pl.griddata(x, y, z, xg, yg, alg, opt[alg])
159
160    --[[
161       - CSA can generate NaNs (only interpolates?!).
162       - DTLI and NNI can generate NaNs for points outside the convex hull
163         of the data points.
164       - NNLI can generate NaNs if a sufficiently thick triangle is not found
165
166       PLplot should be NaN/Inf aware, but changing it now is quite a job...
167       so, instead of not plotting the NaN regions, a weighted average over
168       the neighbors is done. --]]
169
170
171    if alg==pl.GRID_CSA or alg==pl.GRID_DTLI or alg==pl.GRID_NNLI or alg==pl.GRID_NNI then
172      for i = 1, xp do
173        for j = 1, yp do
174          if zg[i][j]~=zg[i][j] then -- average (IDW) over the 8 neighbors
175            zg[i][j] = 0
176            dist = 0
177
178            for ii=i-1, i+1 do
179              if ii<=xp then
180                for jj=j-1, j+1 do
181                  if jj<=yp then
182                    if ii>=1 and jj>=1 and zg[ii][jj]==zg[ii][jj] then
183                      if (math.abs(ii-i) + math.abs(jj-j)) == 1 then
184                        d = 1
185                      else
186                        d = 1.4142
187                      end
188                      zg[i][j] = zg[i][j] + zg[ii][jj]/(d^2)
189                      dist = dist + d
190                    end
191                  end
192                end
193              end
194            end
195            if dist~=0 then
196              zg[i][j] = zg[i][j]/dist
197            else
198              zg[i][j] = zmin
199            end
200          end
201        end
202      end
203    end
204
205    lzM, lzm = pl.MinMax2dGrid(zg)
206
207    if lzm~=lzm then lzm=zmin else lzm = math.min(lzm, zmin) end
208    if lzM~=lzM then lzM=zmax else lzM = math.max(lzM, zmax) end
209
210    -- Increase limits slightly to prevent spurious contours
211    -- due to rounding errors
212    lzm = lzm-0.01
213    lzM = lzM+0.01
214
215    pl.col0(1)
216
217    pl.adv(alg)
218
219    if k==1 then
220      for i = 1, nl do
221        clev[i] = lzm + (lzM-lzm)/(nl-1)*(i-1)
222      end
223
224      pl.env0(xm, xM, ym, yM, 2, 0)
225      pl.col0(15)
226      pl.lab("X", "Y", title[alg])
227      pl.shades(zg, xm, xM, ym, yM, clev, 1, 0, 1, 1)
228      pl.col0(2)
229    else
230      for i = 1, nl do
231        clev[i] = lzm + (lzM-lzm)/(nl-1)*(i-1)
232      end
233
234      cmap1_init()
235      pl.vpor(0, 1, 0, 0.9)
236      pl.wind(-1.1, 0.75, -0.65, 1.20)
237
238      -- For the comparison to be fair, all plots should have the
239      -- same z values, but to get the max/min of the data generated
240      -- by all algorithms would imply two passes. Keep it simple.
241      --
242      -- pl.w3d(1, 1, 1, xm, xM, ym, yM, zmin, zmax, 30, -60)
243
244
245      pl.w3d(1, 1, 1, xm, xM, ym, yM, lzm, lzM, 30, -40)
246      pl.box3("bntu", "X", 0, 0,
247              "bntu", "Y", 0, 0,
248              "bcdfntu", "Z", 0.5, 0)
249      pl.col0(15)
250      pl.lab("", "", title[alg])
251      pl.plot3dc(xg, yg, zg, lor(lor(pl.DRAW_LINEXY, pl.MAG_COLOR), pl.BASE_CONT), clev)
252    end
253  end
254end
255
256pl.plend()
nanonote-example-files/files/lua-plplot-examples/x22.lua
1--[[ $Id: x22.lua 9526 2009-02-13 22:06:13Z smekal $
2
3    Simple vector plot example
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27-- Pairs of points making the line segments used to plot the user defined arrow
28arrow_x = { -0.5, 0.5, 0.3, 0.5, 0.3, 0.5 }
29arrow_y = { 0, 0, 0.2, 0, -0.2, 0 }
30arrow2_x = { -0.5, 0.3, 0.3, 0.5, 0.3, 0.3 }
31arrow2_y = { 0, 0, 0.2, 0, -0.2, 0 }
32
33
34-- Vector plot of the circulation about the origin
35function circulation()
36    nx = 20
37    ny = 20
38    dx = 1
39    dy = 1
40
41    xmin = -nx/2*dx
42    xmax = nx/2*dx
43    ymin = -ny/2*dy
44    ymax = ny/2*dy
45
46  cgrid2 = {}
47    cgrid2["xg"] = {}
48    cgrid2["yg"] = {}
49    cgrid2["nx"] = nx
50    cgrid2["ny"] = ny
51    u = {}
52    v = {}
53
54    -- Create data - circulation around the origin.
55    for i = 1, nx do
56        x = (i-1-nx/2+0.5)*dx
57        cgrid2["xg"][i] = {}
58        cgrid2["yg"][i] = {}
59        u[i] = {}
60        v[i] = {}
61        for j=1, ny do
62            y = (j-1-ny/2+0.5)*dy
63            cgrid2["xg"][i][j] = x
64            cgrid2["yg"][i][j] = y
65            u[i][j] = y
66            v[i][j] = -x
67        end
68    end
69
70    -- Plot vectors with default arrows
71    pl.env(xmin, xmax, ymin, ymax, 0, 0)
72    pl.lab("(x)", "(y)", "#frPLplot Example 22 - circulation")
73    pl.col0(2)
74    pl.vect(u, v, 0, "pltr2", cgrid2 )
75    pl.col0(1)
76end
77
78
79-- Vector plot of flow through a constricted pipe
80function constriction()
81    nx = 20
82    ny = 20
83    dx = 1
84    dy = 1
85
86    xmin = -nx/2*dx
87    xmax = nx/2*dx
88    ymin = -ny/2*dy
89    ymax = ny/2*dy
90
91  cgrid2 = {}
92    cgrid2["xg"] = {}
93    cgrid2["yg"] = {}
94    cgrid2["nx"] = nx
95    cgrid2["ny"] = ny
96    u = {}
97    v = {}
98
99    Q = 2
100    for i = 1, nx do
101        x = (i-1-nx/2+0.5)*dx
102        cgrid2["xg"][i] = {}
103        cgrid2["yg"][i] = {}
104        u[i] = {}
105        v[i] = {}
106        for j = 1, ny do
107            y = (j-1-ny/2+0.5)*dy
108        cgrid2["xg"][i][j] = x
109        cgrid2["yg"][i][j] = y
110        b = ymax/4*(3-math.cos(math.pi*x/xmax))
111            if math.abs(y)<b then
112                dbdx = ymax/4*math.sin(math.pi*x/xmax)*y/b
113                u[i][j] = Q*ymax/b
114                v[i][j] = dbdx*u[i][j]
115            else
116                u[i][j] = 0
117                v[i][j] = 0
118            end
119        end
120    end
121
122    pl.env(xmin, xmax, ymin, ymax, 0, 0)
123    pl.lab("(x)", "(y)", "#frPLplot Example 22 - constriction")
124    pl.col0(2)
125    pl.vect(u, v, -0.5, "pltr2", cgrid2)
126    pl.col0(1)
127end
128
129
130function f2mnmx(f, nx, ny)
131    fmax = f[1][1]
132    fmin = fmax
133
134    for i=1, nx do
135        for j=1, ny do
136        fmax = math.max(fmax, f[i][j])
137        fmin = math.min(fmin, f[i][j])
138        end
139    end
140
141    return fmin, fmax
142end
143
144-- Vector plot of the gradient of a shielded potential (see example 9)
145function potential()
146  nper = 100
147  nlevel = 10
148  nr = 20
149  ntheta = 20
150
151  u = {}
152  v = {}
153  z = {}
154  clevel = {}
155  px = {}
156  py = {}
157
158  cgrid2 = {}
159  cgrid2["xg"] = {}
160  cgrid2["yg"] = {}
161  cgrid2["nx"] = nr
162  cgrid2["ny"] = ntheta
163
164  -- Potential inside a conducting cylinder (or sphere) by method of images.
165  -- Charge 1 is placed at (d1, d1), with image charge at (d2, d2).
166  -- Charge 2 is placed at (d1, -d1), with image charge at (d2, -d2).
167  -- Also put in smoothing term at small distances.
168  rmax = nr
169
170  eps = 2
171
172  q1 = 1
173  d1 = rmax/4
174
175  q1i = -q1*rmax/d1
176  d1i = rmax^2/d1
177
178  q2 = -1
179  d2 = rmax/4
180
181  q2i = -q2*rmax/d2
182  d2i = rmax^2/d2
183
184  for i = 1, nr do
185      r = i - 0.5
186    cgrid2["xg"][i] = {}
187    cgrid2["yg"][i] = {}
188    u[i] = {}
189    v[i] = {}
190    z[i] = {}
191      for j = 1, ntheta do
192        theta = 2*math.pi/(ntheta-1)*(j-0.5)
193        x = r*math.cos(theta)
194        y = r*math.sin(theta)
195        cgrid2["xg"][i][j] = x
196        cgrid2["yg"][i][j] = y
197        div1 = math.sqrt((x-d1)^2 + (y-d1)^2 + eps^2)
198        div1i = math.sqrt((x-d1i)^2 + (y-d1i)^2 + eps^2)
199        div2 = math.sqrt((x-d2)^2 + (y+d2)^2 + eps^2)
200        div2i = math.sqrt((x-d2i)^2 + (y+d2i)^2 + eps^2)
201        z[i][j] = q1/div1 + q1i/div1i + q2/div2 + q2i/div2i
202        u[i][j] = -q1*(x-d1)/div1^3 - q1i*(x-d1i)/div1i^3
203                    -q2*(x-d2)/div2^3 - q2i*(x-d2i)/div2i^3
204        v[i][j] = -q1*(y-d1)/div1^3 - q1i*(y-d1i)/div1i^3
205                    -q2*(y+d2)/div2^3 - q2i*(y+d2i)/div2i^3
206      end
207  end
208
209  xmin, xmax = f2mnmx(cgrid2["xg"], nr, ntheta)
210  ymin, ymax = f2mnmx(cgrid2["yg"], nr, ntheta)
211  zmin, zmax = f2mnmx(z, nr, ntheta)
212
213  pl.env(xmin, xmax, ymin, ymax, 0, 0)
214  pl.lab("(x)", "(y)", "#frPLplot Example 22 - potential gradient vector plot")
215
216  -- Plot contours of the potential
217  dz = (zmax-zmin)/nlevel
218  for i = 1, nlevel do
219      clevel[i] = zmin + (i-0.5)*dz
220  end
221
222  pl.col0(3)
223  pl.lsty(2)
224  pl.cont(z, 1, nr, 1, ntheta, clevel, "pltr2", cgrid2)
225  pl.lsty(1)
226  pl.col0(1)
227
228  -- Plot the vectors of the gradient of the potential
229  pl.col0(2)
230  pl.vect(u, v, 25, "pltr2", cgrid2)
231  pl.col0(1)
232
233  -- Plot the perimeter of the cylinder
234  for i=1, nper do
235    theta = 2*math.pi/(nper-1)*(i-1)
236    px[i] = rmax*math.cos(theta)
237    py[i] = rmax*math.sin(theta)
238  end
239
240  pl.line(px, py)
241end
242
243
244----------------------------------------------------------------------------
245-- main
246--
247-- Generates several simple vector plots.
248----------------------------------------------------------------------------
249
250-- Parse and process command line arguments
251pl.parseopts(arg, pl.PL_PARSE_FULL)
252
253-- Initialize plplot
254pl.init()
255
256circulation()
257
258fill = 0
259
260-- Set arrow style using arrow_x and arrow_y then
261-- plot using these arrows.
262pl.svect(arrow_x, arrow_y, fill)
263constriction()
264
265-- Set arrow style using arrow2_x and arrow2_y then
266-- plot using these filled arrows.
267fill = 1
268pl.svect(arrow2_x, arrow2_y, fill)
269constriction()
270
271potential()
272
273pl.plend()
nanonote-example-files/files/lua-plplot-examples/x23.lua
1--[[ $Id: x23.lua 9533 2009-02-16 22:18:37Z smekal $
2
3    Displays Greek letters and mathematically interesting Unicode ranges
4
5    Copyright (C) 2009 Werner Smekal
6
7    This file is part of PLplot.
8
9    PLplot is free software you can redistribute it and/or modify
10    it under the terms of the GNU General Library Public License as published
11    by the Free Software Foundation either version 2 of the License, or
12    (at your option) any later version.
13
14    PLplot is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17    GNU Library General Public License for more details.
18
19    You should have received a copy of the GNU Library General Public License
20    along with PLplot if not, write to the Free Software
21    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27----------------------------------------------------------------------------
28-- main
29--
30-- Displays Greek letters and mathematically interesting Unicode ranges
31----------------------------------------------------------------------------
32
33Greek = {
34  "#gA","#gB","#gG","#gD","#gE","#gZ","#gY","#gH","#gI","#gK","#gL","#gM",
35  "#gN","#gC","#gO","#gP","#gR","#gS","#gT","#gU","#gF","#gX","#gQ","#gW",
36  "#ga","#gb","#gg","#gd","#ge","#gz","#gy","#gh","#gi","#gk","#gl","#gm",
37  "#gn","#gc","#go","#gp","#gr","#gs","#gt","#gu","#gf","#gx","#gq","#gw"
38}
39
40Type1 = {
41  32, 33, 35, 37, 38,
42  40, 41, 43, 44, 46,
43  47, 48, 49, 50, 51,
44  52, 53, 54, 55, 56,
45  57, 58, 59, 60, 61,
46  62, 63, 91, 93, 95,
47  123, 124, 125, 169, 172,
48  174, 176, 177, 215, 247,
49  402, 913, 914, 915, 916,
50  917, 918, 919, 920, 921,
51  922, 923, 924, 925, 926,
52  927, 928, 929, 931, 932,
53  933, 934, 935, 936, 937,
54  945, 946, 947, 948, 949,
55  950, 951, 952, 953, 954,
56  955, 956, 957, 958, 959,
57  960, 961, 962, 963, 964,
58  965, 966, 967, 968, 969,
59  977, 978, 981, 982, 8226,
60  8230, 8242, 8243, 8254, 8260,
61  8465, 8472, 8476, 8482, 8486,
62  8501, 8592, 8593, 8594, 8595,
63  8596, 8629, 8656, 8657, 8658,
64  8659, 8660, 8704, 8706, 8707,
65  8709, 8710, 8711, 8712, 8713,
66  8715, 8719, 8721, 8722, 8725,
67  8727, 8730, 8733, 8734, 8736,
68  8743, 8744, 8745, 8746, 8747,
69  8756, 8764, 8773, 8776, 8800,
70  8801, 8804, 8805, 8834, 8835,
71  8836, 8838, 8839, 8853, 8855,
72  8869, 8901, 8992, 8993, 9001,
73  9002, 9674, 9824, 9827, 9829,
74  9830
75}
76
77title = {
78  "#<0x10>PLplot Example 23 - Greek Letters",
79  "#<0x10>PLplot Example 23 - Type 1 Symbol Font Glyphs by Unicode (a)",
80  "#<0x10>PLplot Example 23 - Type 1 Symbol Font Glyphs by Unicode (b)",
81  "#<0x10>PLplot Example 23 - Type 1 Symbol Font Glyphs by Unicode (c)",
82  "#<0x10>PLplot Example 23 - Number Forms Unicode Block",
83  "#<0x10>PLplot Example 23 - Arrows Unicode Block (a)",
84  "#<0x10>PLplot Example 23 - Arrows Unicode Block (b)",
85  "#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (a)",
86  "#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (b)",
87  "#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (c)",
88  "#<0x10>PLplot Example 23 - Mathematical Operators Unicode Block (d)"
89}
90
91lo = {
92  0,
93  0,
94  64,
95  128,
96  8531,
97  8592,
98  8656,
99  8704,
100  8768,
101  8832,
102  8896
103}
104
105hi = {
106  48,
107  64,
108  128,
109  166,
110  8580,
111  8656,
112  8704,
113  8768,
114  8832,
115  8896,
116  8960
117}
118
119nxcells = {
120  12,
121  8,
122  8,
123  8,
124  8,
125  8,
126  8,
127  8,
128  8,
129  8,
130  8
131}
132
133nycells = {
134  8,
135  8,
136  8,
137  8,
138  8,
139  8,
140  8,
141  8,
142  8,
143  8,
144  8
145}
146
147-- non-zero values Must be consistent with nxcells and nycells.
148offset = {
149  0,
150  0,
151  64,
152  128,
153  0,
154  0,
155  0,
156  0,
157  0,
158  0,
159  0
160}
161
162-- 30 possible FCI values.
163FCI_COMBINATIONS = 30
164fci = {
165  2147483648,
166  2147483649,
167  2147483650,
168  2147483651,
169  2147483652,
170  2147483664,
171  2147483665,
172  2147483666,
173  2147483667,
174  2147483668,
175  2147483680,
176  2147483681,
177  2147483682,
178  2147483683,
179  2147483684,
180  2147483904,
181  2147483905,
182  2147483906,
183  2147483907,
184  2147483908,
185  2147483920,
186  2147483921,
187  2147483922,
188  2147483923,
189  2147483924,
190  2147483936,
191  2147483937,
192  2147483938,
193  2147483939,
194  2147483940
195}
196
197family = {
198  "sans-serif",
199  "serif",
200  "monospace",
201  "script",
202  "symbol"
203}
204
205style = {
206  "upright",
207  "italic",
208  "oblique"
209}
210
211weight = {
212  "medium",
213  "bold"
214}
215
216-- Parse and process command line arguments
217pl.parseopts(arg, pl.PL_PARSE_FULL)
218
219-- Initialize plplot
220pl.init()
221
222for page=1, 11 do
223  pl.adv(0)
224
225  -- Set up viewport and window
226  pl.vpor(0.02, 0.98, 0.02, 0.90)
227  pl.wind(0, 1, 0, 1)
228  xmin, xmax, ymin, ymax = pl.gspa()
229  pl.schr(0, 0.8)
230  ycharacter_scale = (1-0)/(ymax-ymin)
231
232  -- Factor should be 0.5, but heuristically it turns out to be larger.
233  chardef, charht = pl.gchr()
234  yoffset = charht*ycharacter_scale
235
236  -- Draw the grid using plbox
237  pl.col0(2)
238  deltax = 1.0/nxcells[page]
239  deltay = 1.0/nycells[page]
240  pl.box("bcg", deltax, 0, "bcg", deltay, 0)
241  pl.col0(15)
242  length=hi[page]-lo[page]
243  slice = 1
244
245  for j=nycells[page]-1, -1, -1 do
246    y = (0.5+j)*deltay
247    for i=1, nxcells[page] do
248      x = (i-0.5)*deltax
249      if slice<=length then
250        if page==1 then
251          cmdString = "#" .. Greek[slice]
252        elseif (page>=2) and (page<=4) then
253          cmdString = string.format("##[0x%.4x]", Type1[offset[page]+slice])
254        elseif page>4 then
255          cmdString = string.format("##[0x%.4x]", lo[page]+slice-1)
256        end
257        pl.ptex(x, y+yoffset, 1, 0, 0.5, string.sub(cmdString,2))
258        pl.ptex(x, y-yoffset, 1, 0, 0.5, cmdString)
259      end
260      slice = slice + 1
261    end
262  end
263
264  pl.schr(0, 1)
265
266  -- Page title
267  pl.mtex("t", 1.5, 0.5, 0.5, title[page])
268end
269
270-- Demonstrate methods of getting the current fonts
271fci_old = pl.gfci()
272ifamily, istyle, iweight = pl.gfont()
273print(string.format("For example 23 prior to page 12 the FCI is 0x%x", fci_old))
274print(string.format("For example 23 prior to page 12 the font family, style and weight are %s %s %s",
275                    family[ifamily+1], style[istyle+1], weight[iweight+1]))
276
277for page=12, 16 do
278  dy = 0.030
279
280  pl.adv(0)
281  pl.vpor(0.02, 0.98, 0.02, 0.90)
282  pl.wind(0, 1, 0, 1)
283  pl.sfci(0)
284
285  if page==12 then
286    pl.mtex("t", 1.5, 0.5, 0.5, "#<0x10>PLplot Example 23 - Set Font with plsfci")
287  elseif page==13 then
288    pl.mtex("t", 1.5, 0.5, 0.5, "#<0x10>PLplot Example 23 - Set Font with plsfont")
289  elseif page==14 then
290    pl.mtex("t", 1.5, 0.5, 0.5, "#<0x10>PLplot Example 23 - Set Font with ##<0x8nnnnnnn> construct")
291  elseif page==15 then
292    pl.mtex("t", 1.5, 0.5, 0.5, "#<0x10>PLplot Example 23 - Set Font with ##<0xmn> constructs")
293  elseif page==16 then
294    pl.mtex("t", 1.5, 0.5, 0.5, "#<0x10>PLplot Example 23 - Set Font with ##<FCI COMMAND STRING/> constructs")
295  end
296
297  pl.schr(0, 0.75)
298  for i=1, FCI_COMBINATIONS do
299    family_index = math.mod(i-1, 5)+1
300    style_index = math.mod(math.floor((i-1)/5), 3)+1
301    weight_index = math.mod(math.floor((i-1)/5/3), 2)+1
302    if page==12 then
303      pl.sfci(fci[i])
304      str = string.format("Page 12, %s, %s, %s: The quick brown fox jumps over the lazy dog",
305                          family[family_index], style[style_index], weight[weight_index])
306    elseif page==13 then
307      pl.sfont(family_index-1, style_index-1, weight_index-1)
308      str = string.format("Page 13, %s, %s, %s: The quick brown fox jumps over the lazy dog",
309                          family[family_index], style[style_index], weight[weight_index])
310    elseif page==14 then
311      str = string.format("Page 14, %s, %s, %s: #<0x%x>The quick brown fox jumps over the lazy dog",
312                          family[family_index], style[style_index], weight[weight_index], fci[i])
313    elseif page==15 then
314      str = string.format("Page 15, %s, %s, %s: #<0x%1x0>#<0x%1x1>#<0x%1x2>The quick brown fox jumps over the lazy dog",
315                          family[family_index], style[style_index], weight[weight_index],
316                          family_index-1, style_index-1, weight_index-1)
317    elseif page==16 then
318      str = string.format("Page 16, %s, %s, %s: #<%s/>#<%s/>#<%s/>The quick brown fox jumps over the lazy dog",
319                          family[family_index], style[style_index], weight[weight_index],
320                          family[family_index], style[style_index], weight[weight_index])
321    end
322    pl.ptex(0, 1-(i-0.5)*dy, 1, 0, 0, str)
323  end
324
325  pl.schr(0, 1)
326end
327
328-- Restore defaults
329pl.col0(1)
330
331pl.plend()
nanonote-example-files/files/lua-plplot-examples/x24.lua
1--[[ $Id: x24.lua 9414 2009-01-29 22:48:54Z airwin $
2
3    Unicode Pace Flag
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
23   In Debian, run like this:
24
25   ( TTFDIR=/usr/share/fonts/truetype \
26     PLPLOT_FREETYPE_SANS_FONT=$TTFDIR/arphic/bkai00mp.ttf \
27     PLPLOT_FREETYPE_SERIF_FONT=$TTFDIR/freefont/FreeSerif.ttf \
28     PLPLOT_FREETYPE_MONO_FONT=$TTFDIR/ttf-devanagari-fonts/lohit_hi.ttf \
29     PLPLOT_FREETYPE_SCRIPT_FONT=$TTFDIR/unfonts/UnBatang.ttf \
30     PLPLOT_FREETYPE_SYMBOL_FONT=$TTFDIR/ttf-bengali-fonts/JamrulNormal.ttf \
31     ./x24c -dev png -drvopt smooth=0 -o x24c.png )
32
33   Packages needed:
34
35   ttf-arphic-bkai00mp
36   ttf-freefont
37   ttf-devanagari-fonts
38   ttf-unfonts
39   ttf-bengali-fonts
40--]]
41
42-- initialise Lua bindings for PLplot examples.
43dofile("plplot_examples.lua")
44
45red = { 240, 204, 204, 204, 0, 39, 125 }
46green = { 240, 0, 125, 204, 204, 80, 0 }
47blue = { 240, 0, 0, 0, 0, 204, 125 }
48
49px = { 0, 0, 1, 1 }
50py = { 0, 0.25, 0.25, 0 }
51
52sx = {
53  0.16374,
54  0.15844,
55  0.15255,
56  0.17332,
57  0.50436,
58  0.51721,
59  0.49520,
60  0.48713,
61  0.83976,
62  0.81688,
63  0.82231,
64  0.82647
65}
66
67sy = {
68  0.125,
69  0.375,
70  0.625,
71  0.875,
72  0.125,
73  0.375,
74  0.625,
75  0.875,
76  0.125,
77  0.375,
78  0.625,
79  0.875
80}
81
82
83-- Taken from http://www.columbia.edu/~fdc/pace/
84
85peace = {
86  -- Mandarin
87  "#<0x00>和平",
88  -- Hindi
89  "#<0x20>शांति",
90  -- English
91  "#<0x10>Peace",
92  -- Hebrew
93  "#<0x10>שלום",
94  -- Russian
95  "#<0x10>Мир",
96  -- German
97  "#<0x10>Friede",
98  -- Korean
99  "#<0x30>평화",
100  -- French
101  "#<0x10>Paix",
102  -- Spanish
103  "#<0x10>Paz",
104  -- Arabic
105  "#<0x10>ﺳﻼم",
106  -- Turkish
107  "#<0x10>Barış",
108  -- Kurdish
109  "#<0x10>Hasîtî",
110}
111
112pl.parseopts(arg, pl.PL_PARSE_FULL)
113
114pl.init()
115
116pl.adv(0)
117pl.vpor(0, 1, 0, 1)
118pl.wind(0, 1, 0, 1)
119pl.col0(0)
120pl.box("", 1, 0, "", 1, 0)
121
122pl.scmap0n(7)
123pl.scmap0(red, green, blue)
124
125pl.schr(0, 4)
126pl.font(1)
127
128for i = 1, 4 do
129  pl.col0(i)
130  pl.fill(px, py)
131
132  for j = 1, 4 do
133    py[j] = py[j] + 1/4
134  end
135end
136
137pl.col0(0)
138for i = 1, 12 do
139  pl.ptex(sx[i], sy[i], 1, 0, 0.5, peace[i])
140end
141
142pl.plend()
nanonote-example-files/files/lua-plplot-examples/x25.lua
1--[[ $Id: x25.lua 10668 2009-12-02 08:38:49Z airwin $
2
3    Filling and clipping polygons.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27--------------------------------------------------------------------------
28-- main
29--
30-- Test program for filling polygons and proper clipping
31--------------------------------------------------------------------------
32
33xextreme = {}
34yextreme ={}
35x0 = {}
36y0 = {}
37
38-- Parse and process command line arguments
39pl.parseopts(arg, pl.PL_PARSE_FULL)
40
41-- Initialize plplot
42pl.ssub(3, 3)
43pl.init()
44
45xextreme = { { -120, 120 }, { -120, 120 }, { -120, 120 }, { -80, 80 }, { -220, -120 },
46             { -20, 20 }, { -20, 20 }, { -80, 80 }, { 20, 120 } }
47
48yextreme = { { -120, 120 }, { 20, 120 }, { -20, 120 }, { -20, 120 }, { -120, 120 },
49             { -120, 120 }, { -20, 20 }, { -80, 80 }, { -120, 120 } }
50
51for k = 1, 2 do
52for j = 1, 4 do
53  if j==1 then
54    -- Polygon 1: a diamond
55    x0 = { 0, -100, 0, 100 }
56    y0 = { -100, 0, 100, 0}
57  end
58  if j==2 then
59    -- Polygon 1: a diamond - reverse direction
60    x0 = { 100, 0, -100, 0 }
61    y0 = { 0, 100, 0, -100}
62  end
63  if j==3 then
64    -- Polygon 2: a square with punctures
65    x0 = { -100, -100, 80, -100, -100, -80, 0, 80, 100, 100 }
66    y0 = { -100, -80, 0, 80, 100, 100, 80, 100, 100, -100}
67  end
68  if j==4 then
69    -- Polygon 2: a square with punctures - reversed direction
70    x0 = { 100, 100, 80, 0, -80, -100, -100, 80, -100, -100 }
71    y0 = { -100, 100, 100, 80, 100, 100, 80, 0, -80, -100}
72  end
73
74  for i = 1, 9 do
75    pl.adv(0)
76    pl.vsta()
77    pl.wind(xextreme[i][1], xextreme[i][2], yextreme[i][1], yextreme[i][2])
78
79    pl.col0(2)
80    pl.box("bc", 1, 0, "bcnv", 10, 0)
81    pl.col0(1)
82    pl.psty(0)
83    if k==1 then
84      pl.fill(x0, y0)
85    else
86      pl.gradient(x0, y0, 45.)
87    end
88    pl.col0(2)
89    pl.lsty(1)
90    pl.line(x0, y0)
91  end
92end
93end
94
95-- Don't forget to call plend() to finish off!
96pl.plend()
nanonote-example-files/files/lua-plplot-examples/x26.lua
1--[[ -*- coding: utf-8 -*-
2
3   $Id: x26.lua 9506 2009-02-11 08:23:29Z smekal $
4
5   Multi-lingual version of the first page of example 4.
6
7   Copyright (C) 2009 Werner Smekal
8
9   Thanks to the following for providing translated strings for this example:
10   Valery Pipin (Russian)
11
12   This file is part of PLplot.
13
14   PLplot is free software you can redistribute it and/or modify
15   it under the terms of the GNU General Library Public License as published
16   by the Free Software Foundation either version 2 of the License, or
17   (at your option) any later version.
18
19   PLplot is distributed in the hope that it will be useful,
20   but WITHOUT ANY WARRANTY without even the implied warranty of
21   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22   GNU Library General Public License for more details.
23
24   You should have received a copy of the GNU Library General Public License
25   along with PLplot if not, write to the Free Software
26   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27--]]
28
29
30--[[
31  This example designed just for devices (e.g., psttfc and the
32  cairo-related devices) that use the pango and fontconfig libraries. The
33  best choice of glyph is selected by fontconfig and automatically rendered
34  by pango in way that is sensitive to complex text layout (CTL) language
35  issues for each unicode character in this example. Of course, you must
36  have the appropriate TrueType fonts installed to have access to all the
37  required glyphs.
38
39  Translation instructions: The strings to be translated are given by
40  x_label, y_label, alty_label, title_label, and line_label below. The
41  encoding used must be UTF-8.
42
43  The following strings to be translated involve some scientific/mathematical
44  jargon which is now discussed further to help translators.
45
46  (1) dB is a decibel unit, see http://en.wikipedia.org/wiki/Decibel .
47  (2) degrees is an angular measure, see
48      http://en.wikipedia.org/wiki/Degree_(angle) .
49  (3) low-pass filter is one that transmits (passes) low frequencies.
50  (4) pole is in the mathematical sense, see
51      http://en.wikipedia.org/wiki/Pole_(complex_analysis) . "Single Pole"
52      means a particular mathematical transformation of the filter function has
53      a single pole, see
54      http://ccrma.stanford.edu/~jos/filters/Pole_Zero_Analysis_I.html .
55      Furthermore, a single-pole filter must have an inverse square decline
56      (or -20 db/decade). Since the filter plotted here does have that
57      characteristic, it must by definition be a single-pole filter, see also
58      http://www-k.ext.ti.com/SRVS/Data/ti/KnowledgeBases/analog/document/faqs/1p.htm
59  (5) decade represents a factor of 10, see
60      http://en.wikipedia.org/wiki/Decade_(log_scale) .
61--]]
62
63-- initialise Lua bindings for PLplot examples.
64dofile("plplot_examples.lua")
65
66x_label = { "Frequency", "Частота" }
67y_label = { "Amplitude (dB)", "Амплитуда (dB)" }
68alty_label = { "Phase shift (degrees)", "Фазовый сдвиг (градусы)" }
69title_label = { "Single Pole Low-Pass Filter", "Однополюсный Низко-Частотный Фильтр" }
70line_label = { "-20 dB/decade", "-20 dB/десяток" }
71
72
73----------------------------------------------------------------------------
74-- plot1
75--
76-- Log-linear plot.
77----------------------------------------------------------------------------
78
79function plot1(typ, x_label, y_label, alty_label, title_label, line_label)
80  freql = {}
81  ampl = {}
82  phase = {}
83
84  pl.adv(0)
85
86  -- Set up data for log plot
87
88  f0 = 1
89  for i = 1, 101 do
90    freql[i] = -2 + (i-1)/20
91    freq = 10^freql[i]
92    ampl[i] = 20 * math.log10(1/math.sqrt(1+(freq/f0)^2))
93    phase[i] = -180/math.pi*math.atan(freq/f0)
94  end
95
96  pl.vpor(0.15, 0.85, 0.1, 0.9)
97  pl.wind(-2, 3, -80, 0)
98
99  -- Try different axis and labelling styles.
100  pl.col0(1)
101  if typ==0 then
102    pl.box("bclnst", 0, 0, "bnstv", 0, 0)
103  else
104    pl.box("bcfghlnst", 0, 0, "bcghnstv", 0, 0)
105  end
106
107  -- Plot ampl vs freq
108  pl.col0(2)
109  pl.line(freql, ampl)
110  pl.col0(1)
111  pl.ptex(1.6, -30, 1, -20, 0.5, line_label)
112
113  -- Put labels on
114  pl.col0(1)
115  pl.mtex("b", 3.2, 0.5, 0.5, x_label)
116  pl.mtex("t", 2, 0.5, 0.5, title_label)
117  pl.col0(2)
118  pl.mtex("l", 5, 0.5, 0.5, y_label)
119
120  -- For the gridless case, put phase vs freq on same plot
121  if typ==0 then
122    pl.col0(1)
123    pl.wind(-2, 3, -100, 0)
124    pl.box("", 0, 0, "cmstv", 30, 3)
125    pl.col0(3)
126    pl.line(freql, phase)
127    pl.col0(3)
128    pl.mtex("r", 5, 0.5, 0.5, alty_label)
129  end
130end
131
132
133----------------------------------------------------------------------------
134-- main
135--
136-- Illustration of logarithmic axes, and redefinition of window.
137----------------------------------------------------------------------------
138
139-- Parse and process command line arguments
140pl.parseopts(arg, pl.PL_PARSE_FULL)
141
142-- Initialize plplot
143pl.init()
144pl.font(2)
145
146-- Make log plots using two different styles.
147for i = 1, 2 do
148  plot1(0, x_label[i], y_label[i], alty_label[i], title_label[i], line_label[i])
149end
150
151pl.plend()
nanonote-example-files/files/lua-plplot-examples/x27.lua
1--[[ $Id: x27.lua 9526 2009-02-13 22:06:13Z smekal $
2
3    Drawing "spirograph" curves - epitrochoids, cycolids, roulettes
4
5   Copyright (C) 2009 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27
28function cycloid()
29  -- TODO
30end
31
32
33function spiro( params )
34  NPNT = 20000
35  xcoord = {}
36  ycoord = {}
37
38  -- Fill the coordinates
39  windings = params[4]
40  steps = math.floor(NPNT/windings)
41  dphi = 8*math.acos(-1)/steps
42
43  xmin = 0 -- This initialisation is safe!
44  xmax = 0
45  ymin = 0
46  ymax = 0
47
48  for i = 1, windings*steps+1 do
49    phi = (i-1) * dphi
50    phiw = (params[1]-params[2])/params[2]*phi
51    xcoord[i] = (params[1]-params[2])*math.cos(phi) + params[3]*math.cos(phiw)
52    ycoord[i] = (params[1]-params[2])*math.sin(phi) - params[3]*math.sin(phiw)
53
54    if xmin>xcoord[i] then xmin = xcoord[i] end
55    if xmax<xcoord[i] then xmax = xcoord[i] end
56    if ymin>ycoord[i] then ymin = ycoord[i] end
57    if ymax<ycoord[i] then ymax = ycoord[i] end
58  end
59
60  if (xmax-xmin)>(ymax-ymin) then
61    scale = xmax - xmin
62  else
63    scale = ymax - ymin
64  end
65  xmin = -0.65*scale
66  xmax = 0.65*scale
67  ymin = -0.65*scale
68  ymax = 0.65*scale
69
70  pl.wind(xmin, xmax, ymin, ymax)
71
72  pl.col0(1)
73  pl.line(xcoord, ycoord)
74end
75
76
77----------------------------------------------------------------------------
78-- main
79--
80-- Generates two kinds of plots:
81-- - construction of a cycloid (animated)
82-- - series of epitrochoids and hypotrochoids
83----------------------------------------------------------------------------
84
85-- R, r, p, N
86params = {
87  { 21, 7, 7, 3 }, -- Deltoid
88  { 21, 7, 10, 3 },
89  { 21, -7, 10, 3 },
90  { 20, 3, 7, 20 },
91  { 20, 3, 10, 20 },
92  { 20, -3, 10, 20 },
93  { 20, 13, 7, 20 },
94  { 20, 13, 20, 20 },
95  { 20,-13, 20, 20 } }
96
97-- plplot initialization
98
99-- Parse and process command line arguments
100pl.parseopts(arg, pl.PL_PARSE_FULL)
101
102-- Initialize plplot
103pl.init()
104
105-- Illustrate the construction of a cycloid
106cycloid()
107
108-- Loop over the various curves
109-- First an overview, then all curves one by one
110
111pl.ssub(3, 3) -- Three by three window
112
113for i = 1, 9 do
114  pl.adv(0)
115  pl.vpor(0, 1, 0, 1)
116  spiro(params[i])
117end
118
119pl.adv(0)
120pl.ssub(1, 1) -- One window per curve
121
122for i = 1, 9 do
123  pl.adv(0)
124  pl.vpor(0, 1, 0, 1)
125  spiro(params[i])
126end
127
128-- Don't forget to call plend() to finish off!
129pl.plend()
nanonote-example-files/files/lua-plplot-examples/x28.lua
1--[[ $Id: x28.lua 10710 2009-12-08 06:51:27Z airwin $
2
3    pl.mtex3, plptex3 demo.
4
5   Copyright (C) 2009 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24
25-- initialise Lua bindings for PLplot examples.
26dofile("plplot_examples.lua")
27
28-- Choose these values to correspond to tick marks.
29XPTS = 2
30YPTS = 2
31NREVOLUTION = 16
32NROTATION = 8
33NSHEAR = 8
34
35----------------------------------------------------------------------------
36-- main
37--
38-- Demonstrates plotting text in 3D.
39----------------------------------------------------------------------------
40
41xmin=0
42xmax=1
43xmid = 0.5*(xmax + xmin)
44xrange = xmax - xmin
45ymin=0
46ymax=1
47ymid = 0.5*(ymax + ymin)
48yrange = ymax - ymin
49zmin=0
50zmax=1
51zmid = 0.5*(zmax + zmin)
52zrange = zmax - zmin
53ysmin = ymin + 0.1 * yrange
54ysmax = ymax - 0.1 * yrange
55ysrange = ysmax - ysmin
56dysrot = ysrange / ( NROTATION - 1 )
57dysshear = ysrange / ( NSHEAR - 1 )
58zsmin = zmin + 0.1 * zrange
59zsmax = zmax - 0.1 * zrange
60zsrange = zsmax - zsmin
61dzsrot = zsrange / ( NROTATION - 1 )
62dzsshear = zsrange / ( NSHEAR - 1 )
63
64pstring = "The future of our civilization depends on software freedom."
65
66-- Allocate and define the minimal x, y, and z to insure 3D box
67x = {}
68y = {}
69z = {}
70
71for i = 1, XPTS do
72  x[i] = xmin + (i-1) * (xmax-xmin)/(XPTS-1)
73end
74
75for j = 1, YPTS do
76 y[j] = ymin + (j-1) * (ymax-ymin)/(YPTS-1)
77end
78
79for i = 1, XPTS do
80  z[i] = {}
81  for j = 1, YPTS do
82    z[i][j] = 0
83  end
84end
85
86-- Parse and process command line arguments
87pl.parseopts(arg, pl.PL_PARSE_FULL)
88
89pl.init()
90
91-- Page 1: Demonstrate inclination and shear capability pattern.
92pl.adv(0)
93pl.vpor(-0.15, 1.15, -0.05, 1.05)
94pl.wind(-1.2, 1.2, -0.8, 1.5)
95pl.w3d(1, 1, 1, xmin, xmax, ymin, ymax, zmin, zmax, 20, 45)
96
97pl.col0(2)
98pl.box3("b", "", xmax-xmin, 0,
99        "b", "", ymax-ymin, 0,
100        "bcd", "", zmax-zmin, 0)
101
102-- z = zmin.
103pl.schr(0, 1)
104for i = 1, NREVOLUTION do
105  omega = 2*math.pi*(i-1)/NREVOLUTION
106  sin_omega = math.sin(omega)
107  cos_omega = math.cos(omega)
108  x_inclination = 0.5*xrange*cos_omega
109  y_inclination = 0.5*yrange*sin_omega
110  z_inclination = 0
111  x_shear = -0.5*xrange*sin_omega
112  y_shear = 0.5*yrange*cos_omega
113  z_shear = 0
114  pl.ptex3( xmid, ymid, zmin, x_inclination, y_inclination, z_inclination,
115           x_shear, y_shear, z_shear, 0, " revolution")
116end
117
118-- x = xmax.
119pl.schr(0, 1)
120for i = 1, NREVOLUTION do
121  omega = 2.*math.pi*(i-1)/NREVOLUTION
122  sin_omega = math.sin(omega)
123  cos_omega = math.cos(omega)
124  x_inclination = 0.
125  y_inclination = -0.5*yrange*cos_omega
126  z_inclination = 0.5*zrange*sin_omega
127  x_shear = 0
128  y_shear = 0.5*yrange*sin_omega
129  z_shear = 0.5*zrange*cos_omega
130  pl.ptex3(xmax, ymid, zmid, x_inclination, y_inclination, z_inclination,
131           x_shear, y_shear, z_shear, 0, " revolution")
132end
133
134-- y = ymax.
135pl.schr(0, 1)
136for i = 1, NREVOLUTION do
137  omega = 2.*math.pi*(i-1)/NREVOLUTION
138  sin_omega = math.sin(omega)
139  cos_omega = math.cos(omega)
140  x_inclination = 0.5*xrange*cos_omega
141  y_inclination = 0.
142  z_inclination = 0.5*zrange*sin_omega
143  x_shear = -0.5*xrange*sin_omega
144  y_shear = 0.
145  z_shear = 0.5*zrange*cos_omega
146  pl.ptex3(xmid, ymax, zmid, x_inclination, y_inclination, z_inclination,
147           x_shear, y_shear, z_shear, 0, " revolution")
148end
149
150-- Draw minimal 3D grid to finish defining the 3D box.
151pl.mesh(x, y, z, pl.DRAW_LINEXY)
152
153-- Page 2: Demonstrate rotation of string around its axis.
154pl.adv(0)
155pl.vpor(-0.15, 1.15, -0.05, 1.05)
156pl.wind(-1.2, 1.2, -0.8, 1.5)
157pl.w3d(1, 1, 1, xmin, xmax, ymin, ymax, zmin, zmax, 20, 45)
158
159pl.col0(2)
160pl.box3("b", "", xmax-xmin, 0,
161        "b", "", ymax-ymin, 0,
162        "bcd", "", zmax-zmin, 0)
163
164-- y = ymax.
165pl.schr(0, 1)
166x_inclination = 1
167y_inclination = 0
168z_inclination = 0
169x_shear = 0
170for i = 1, NROTATION do
171  omega = 2.*math.pi*(i-1)/NROTATION
172  sin_omega = math.sin(omega)
173  cos_omega = math.cos(omega)
174  y_shear = 0.5*yrange*sin_omega
175  z_shear = 0.5*zrange*cos_omega
176  zs = zsmax - dzsrot * (i-1)
177  pl.ptex3(xmid, ymax, zs,
178           x_inclination, y_inclination, z_inclination,
179           x_shear, y_shear, z_shear,
180           0.5, "rotation for y = y#dmax#u")
181end
182
183-- x = xmax.
184pl.schr(0, 1)
185x_inclination = 0
186y_inclination = -1
187z_inclination = 0
188y_shear = 0
189for i = 1, NROTATION do
190  omega = 2.*math.pi*(i-1)/NROTATION
191  sin_omega = math.sin(omega)
192  cos_omega = math.cos(omega)
193  x_shear = 0.5*xrange*sin_omega
194  z_shear = 0.5*zrange*cos_omega
195  zs = zsmax - dzsrot * (i-1)
196  pl.ptex3(xmax, ymid, zs,
197           x_inclination, y_inclination, z_inclination,
198           x_shear, y_shear, z_shear,
199           0.5, "rotation for x = x#dmax#u")
200end
201
202-- z = zmin.
203pl.schr(0, 1)
204x_inclination = 1
205y_inclination = 0
206z_inclination = 0
207x_shear = 0
208for i = 1, NROTATION do
209  omega = 2.*math.pi*(i-1)/NROTATION
210  sin_omega = math.sin(omega)
211  cos_omega = math.cos(omega)
212  y_shear = 0.5*yrange*cos_omega
213  z_shear = 0.5*zrange*sin_omega
214  ys = ysmax - dysrot * (i-1)
215  pl.ptex3(xmid, ys, zmin,
216           x_inclination, y_inclination, z_inclination,
217           x_shear, y_shear, z_shear,
218           0.5, "rotation for z = z#dmin#u")
219end
220
221-- Draw minimal 3D grid to finish defining the 3D box.
222pl.mesh(x, y, z, pl.DRAW_LINEXY)
223
224-- Page 3: Demonstrate shear of string along its axis.
225-- Work around xcairo and pngcairo (but not pscairo) problems for
226-- shear vector too close to axis of string. (N.B. no workaround
227-- would be domega = 0.)
228domega = 0.05
229pl.adv(0)
230pl.vpor(-0.15, 1.15, -0.05, 1.05)
231pl.wind(-1.2, 1.2, -0.8, 1.5)
232pl.w3d(1, 1, 1, xmin, xmax, ymin, ymax, zmin, zmax, 20, 45)
233
234pl.col0(2)
235pl.box3("b", "", xmax-xmin, 0,
236        "b", "", ymax-ymin, 0,
237        "bcd", "", zmax-zmin, 0)
238
239-- y = ymax.
240pl.schr(0, 1)
241x_inclination = 1
242y_inclination = 0
243z_inclination = 0
244y_shear = 0
245for i = 1, NSHEAR do
246  omega = domega + 2.*math.pi*(i-1)/NSHEAR
247  sin_omega = math.sin(omega)
248  cos_omega = math.cos(omega)
249  x_shear = 0.5*xrange*sin_omega
250  z_shear = 0.5*zrange*cos_omega
251  zs = zsmax - dzsshear * (i-1)
252  pl.ptex3(xmid, ymax, zs,
253           x_inclination, y_inclination, z_inclination,
254           x_shear, y_shear, z_shear,
255           0.5, "shear for y = y#dmax#u")
256end
257
258-- x = xmax.
259pl.schr(0, 1)
260x_inclination = 0
261y_inclination = -1
262z_inclination = 0
263x_shear = 0
264for i = 1, NSHEAR do
265  omega = domega + 2.*math.pi*(i-1)/NSHEAR
266  sin_omega = math.sin(omega)
267  cos_omega = math.cos(omega)
268  y_shear = -0.5*yrange*sin_omega
269  z_shear = 0.5*zrange*cos_omega
270  zs = zsmax - dzsshear * (i-1)
271  pl.ptex3(xmax, ymid, zs,
272           x_inclination, y_inclination, z_inclination,
273           x_shear, y_shear, z_shear,
274           0.5, "shear for x = x#dmax#u")
275end
276
277-- z = zmin.
278pl.schr(0, 1)
279x_inclination = 1
280y_inclination = 0
281z_inclination = 0
282z_shear = 0
283for i = 1, NSHEAR do
284  omega = domega + 2.*math.pi*(i-1)/NSHEAR
285  sin_omega = math.sin(omega)
286  cos_omega = math.cos(omega)
287  y_shear = 0.5*yrange*cos_omega
288  x_shear = 0.5*xrange*sin_omega
289  ys = ysmax - dysshear * (i-1)
290  pl.ptex3(xmid, ys, zmin,
291           x_inclination, y_inclination, z_inclination,
292           x_shear, y_shear, z_shear,
293           0.5, "shear for z = z#dmin#u")
294end
295
296-- Draw minimal 3D grid to finish defining the 3D box.
297pl.mesh(x, y, z, pl.DRAW_LINEXY)
298
299-- Page 4: Demonstrate drawing a string on a 3D path.
300pl.adv(0)
301pl.vpor(-0.15, 1.15, -0.05, 1.05)
302pl.wind(-1.2, 1.2, -0.8, 1.5)
303pl.w3d(1, 1, 1, xmin, xmax, ymin, ymax, zmin, zmax, 40, -30)
304
305pl.col0(2)
306pl.box3("b", "", xmax-xmin, 0,
307        "b", "", ymax-ymin, 0,
308        "bcd", "", zmax-zmin, 0)
309
310pl.schr(0, 1.2)
311-- domega controls the spacing between the various characters of the
312-- string and also the maximum value of omega for the given number
313-- of characters in *pstring.
314domega = 2.*math.pi/string.len(pstring)
315omega = 0
316
317-- 3D function is a helix of the given radius and pitch
318radius = 0.5
319pitch = 1/(2*math.pi)
320
321for i = 1, string.len(pstring) do
322  sin_omega = math.sin(omega)
323  cos_omega = math.cos(omega)
324  xpos = xmid + radius*sin_omega
325  ypos = ymid - radius*cos_omega
326  zpos = zmin + pitch*omega
327
328  -- In general, the inclination is proportional to the derivative of
329  --the position wrt theta.
330  x_inclination = radius*cos_omega
331  y_inclination = radius*sin_omega
332  z_inclination = pitch
333
334  -- The shear vector should be perpendicular to the 3D line with Z
335  -- component maximized, but for low pitch a good approximation is
336  --a constant vector that is parallel to the Z axis.
337  x_shear = 0
338  y_shear = 0
339  z_shear = 1
340  pl.ptex3(xpos, ypos, zpos, x_inclination, y_inclination, z_inclination,
341           x_shear, y_shear, z_shear, 0.5, string.sub(pstring, i, i))
342  omega = omega + domega
343end
344
345-- Draw minimal 3D grid to finish defining the 3D box.
346pl.mesh(x, y, z, pl.DRAW_LINEXY)
347
348-- Page 5: Demonstrate pl.mtex3 axis labelling capability
349pl.adv(0)
350pl.vpor(-0.15, 1.15, -0.05, 1.05)
351pl.wind(-1.2, 1.2, -0.8, 1.5)
352pl.w3d(1, 1, 1, xmin, xmax, ymin, ymax, zmin, zmax, 20, 45)
353
354pl.col0(2)
355pl.box3("b", "", xmax-xmin, 0,
356        "b", "", ymax-ymin, 0,
357        "bcd", "", zmax-zmin, 0)
358
359pl.schr(0, 1)
360pl.mtex3("xp", 3, 0.5, 0.5, "Arbitrarily displaced")
361pl.mtex3("xp", 4.5, 0.5, 0.5, "primary X-axis label")
362pl.mtex3("xs", -2.5, 0.5, 0.5, "Arbitrarily displaced")
363pl.mtex3("xs", -1, 0.5, 0.5, "secondary X-axis label")
364pl.mtex3("yp", 3, 0.5, 0.5, "Arbitrarily displaced")
365pl.mtex3("yp", 4.5, 0.5, 0.5, "primary Y-axis label")
366pl.mtex3("ys", -2.5, 0.5, 0.5, "Arbitrarily displaced")
367pl.mtex3("ys", -1, 0.5, 0.5, "secondary Y-axis label")
368pl.mtex3("zp", 4.5, 0.5, 0.5, "Arbitrarily displaced")
369pl.mtex3("zp", 3, 0.5, 0.5, "primary Z-axis label")
370pl.mtex3("zs", -2.5, 0.5, 0.5, "Arbitrarily displaced")
371pl.mtex3("zs", -1, 0.5, 0.5, "secondary Z-axis label")
372
373-- Draw minimal 3D grid to finish defining the 3D box.
374pl.mesh(x, y, z, pl.DRAW_LINEXY)
375
376pl.plend()
nanonote-example-files/files/lua-plplot-examples/x29.lua
1--[[ $Id: x29.lua 10299 2009-08-19 17:54:27Z smekal $
2
3       Sample plots using date / time formatting for axes
4
5  Copyright (C) 2009 Werner Smekal
6
7  This file is part of PLplot.
8
9    PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24
25-- initialise Lua bindings for PLplot examples.
26dofile("plplot_examples.lua")
27
28
29
30-- Plot a model diurnal cycle of temperature
31function plot1()
32  x = {}
33  y = {}
34
35  xerr1 = {}
36  xerr2 = {}
37  yerr1 = {}
38  yerr2 = {}
39  -- Data points every 10 minutes for 1 day
40  npts = 73
41
42  xmin = 0
43  xmax = 60*60*24 -- Number of seconds in a day
44  ymin = 10
45  ymax = 20
46
47  for i = 1, npts do
48    x[i] = xmax*((i-1)/npts)
49    y[i] = 15 - 5*math.cos(2*math.pi*((i-1)/npts))
50    -- Set x error bars to +/- 5 minute
51    xerr1[i] = x[i]-60*5
52    xerr2[i] = x[i]+60*5
53    -- Set y error bars to +/- 0.1 deg C
54    yerr1[i] = y[i]-0.1
55    yerr2[i] = y[i]+0.1
56  end
57
58  pl.adv(0)
59
60  -- Rescale major ticks marks by 0.5
61  pl.smaj(0, 0.5)
62  -- Rescale minor ticks and error bar marks by 0.5
63  pl.smin(0, 0.5)
64
65  pl.vsta()
66  pl.wind(xmin, xmax, ymin, ymax)
67
68  -- Draw a box with ticks spaced every 3 hour in X and 1 degree C in Y.
69  pl.col0(1)
70  -- Set time format to be hours:minutes
71  pl.timefmt("%H:%M")
72  pl.box("bcnstd", 3*60*60, 3, "bcnstv", 1, 5)
73
74  pl.col0(3)
75  pl.lab("Time (hours:mins)", "Temperature (degC)", "@frPLplot Example 29 - Daily temperature")
76
77  pl.col0(4)
78
79  pl.line(x, y)
80  pl.col0(2)
81  pl.errx(xerr1, xerr2, y)
82  pl.col0(3)
83  pl.erry(x, yerr1, yerr2)
84
85  -- Rescale major / minor tick marks back to default
86  pl.smin(0, 1)
87  pl.smaj(0, 1)
88end
89
90
91-- Plot the number of hours of daylight as a function of day for a year
92function plot2()
93  x = {}
94  y = {}
95
96  -- Latitude for London
97  lat = 51.5
98
99  npts = 365
100
101  xmin = 0
102  xmax = npts*60*60*24
103  ymin = 0
104  ymax = 24
105
106  -- Formula for hours of daylight from
107  -- "A Model Comparison for Daylength as a Function of Latitude and
108  -- Day of the Year", 1995, Ecological Modelling, 80, pp 87-95.
109  for j = 1, npts do
110    x[j] = (j-1)*60*60*24
111    p = math.asin(0.39795*math.cos(0.2163108 + 2*math.atan(0.9671396*math.tan(0.00860*(j-1-186)))))
112    d = 24 - (24/math.pi)*
113      math.acos( (math.sin(0.8333*math.pi/180) + math.sin(lat*math.pi/180)*math.sin(p)) /
114        (math.cos(lat*math.pi/180)*math.cos(p)) )
115    y[j] = d
116  end
117
118  pl.col0(1)
119  -- Set time format to be abbreviated month name followed by day of month
120  pl.timefmt("%b %d")
121  pl.prec(1, 1)
122  pl.env(xmin, xmax, ymin, ymax, 0, 40)
123
124
125  pl.col0(3)
126  pl.lab("Date", "Hours of daylight", "@frPLplot Example 29 - Hours of daylight at 51.5N")
127
128  pl.col0(4)
129
130  pl.line(x, y)
131
132  pl.prec(0, 0)
133end
134
135
136function plot3()
137  x = {}
138  y = {}
139
140  tstart = 1133395200
141
142  npts = 62
143
144  xmin = tstart
145  xmax = xmin + npts*60*60*24
146  ymin = 0
147  ymax = 5
148
149  for i = 1, npts do
150    x[i] = xmin + (i-1)*60*60*24
151    y[i] = 1 + math.sin(2*math.pi*(i-1)/7) + math.exp(math.min(i-1,npts-i+1)/31)
152  end
153  pl.adv(0)
154
155  pl.vsta()
156  pl.wind(xmin, xmax, ymin, ymax)
157
158  pl.col0(1)
159  -- Set time format to be ISO 8601 standard YYYY-MM-DD. Note that this is
160  --equivalent to %f for C99 compliant implementations of strftime.
161  pl.timefmt("%Y-%m-%d")
162  -- Draw a box with ticks spaced every 14 days in X and 1 hour in Y.
163  pl.box("bcnstd", 14*24*60*60,14, "bcnstv", 1, 4)
164
165  pl.col0(3)
166  pl.lab("Date", "Hours of television watched", "@frPLplot Example 29 - Hours of television watched in Dec 2005 / Jan 2006")
167
168  pl.col0(4)
169
170  -- Rescale symbol size (used by plpoin) by 0.5
171  pl.ssym(0, 0.5)
172  pl.poin(x, y, 2)
173  pl.line(x, y)
174end
175
176
177function plot4()
178  -- TAI-UTC (seconds) as a function of time.
179  -- Use Besselian epochs as the continuous time interval just to prove
180  -- this does not introduce any issues.
181
182  x = {}
183  y = {}
184
185  -- Use the definition given in http://en.wikipedia.org/wiki/Besselian_epoch
186  -- B = 1900. + (JD -2415020.31352)/365.242198781
187  -- ==> (as calculated with aid of "bc -l" command)
188  -- B = (MJD + 678940.364163900)/365.242198781
189  -- ==>
190  -- MJD = B*365.24219878 - 678940.364163900
191  scale = 365.242198781
192  offset1 = -678940
193  offset2 = -0.3641639
194  pl.configtime(scale, offset1, offset2, 0, 0, 0, 0, 0, 0, 0, 0.)
195
196  for kind = 0, 6 do
197    if kind == 0 then
198      xmin = pl.ctime(1950, 0, 2, 0, 0, 0)
199      xmax = pl.ctime(2020, 0, 2, 0, 0, 0)
200      npts = 70*12 + 1
201      ymin = 0
202      ymax = 36
203      time_format = "%Y%"
204      if_TAI_time_format = 1
205      title_suffix = "from 1950 to 2020"
206      xtitle = "Year"
207      xlabel_step = 10
208    end
209    if kind==1 or kind==2 then
210      xmin = pl.ctime(1961, 7, 1, 0, 0, 1.64757-0.20)
211      xmax = pl.ctime(1961, 7, 1, 0, 0, 1.64757+0.20)
212      npts = 1001
213      ymin = 1.625
214      ymax = 1.725
215      time_format = "%S%2%"
216      title_suffix = "near 1961-08-01 (TAI)"
217      xlabel_step = 0.05/(scale*86400)
218      if kind==1 then
219        if_TAI_time_format = 1
220        xtitle = "Seconds (TAI)"
221      else
222        if_TAI_time_format = 0
223        xtitle = "Seconds (TAI) labelled with corresponding UTC"
224      end
225    end
226    if kind==3 or kind==4 then
227      xmin = pl.ctime(1963, 10, 1, 0, 0, 2.6972788-0.20)
228      xmax = pl.ctime(1963, 10, 1, 0, 0, 2.6972788+0.20)
229      npts = 1001
230      ymin = 2.55
231      ymax = 2.75
232      time_format = "%S%2%"
233      title_suffix = "near 1963-11-01 (TAI)"
234      xlabel_step = 0.05/(scale*86400)
235      if kind==3 then
236                if_TAI_time_format = 1
237                xtitle = "Seconds (TAI)"
238      else
239                if_TAI_time_format = 0
240                xtitle = "Seconds (TAI) labelled with corresponding UTC"
241      end
242    end
243    if kind==5 or kind==6 then
244      xmin = pl.ctime(2009, 0, 1, 0, 0, 34-5)
245      xmax = pl.ctime(2009, 0, 1, 0, 0, 34+5)
246      npts = 1001
247      ymin = 32.5
248      ymax = 34.5
249      time_format = "%S%2%"
250      title_suffix = "near 2009-01-01 (TAI)"
251      xlabel_step = 1/(scale*86400)
252      if kind==5 then
253        if_TAI_time_format = 1
254        xtitle = "Seconds (TAI)"
255      else
256        if_TAI_time_format = 0
257        xtitle = "Seconds (TAI) labelled with corresponding UTC"
258      end
259    end
260
261    for i = 1, npts do
262      x[i] = xmin + (i-1)*(xmax-xmin)/(npts-1)
263      pl.configtime(scale, offset1, offset2, 0, 0, 0, 0, 0, 0, 0, 0)
264      tai = x[i]
265      tai_year, tai_month, tai_day, tai_hour, tai_min, tai_sec = pl.btime(tai)
266      pl.configtime(scale, offset1, offset2, 2, 0, 0, 0, 0, 0, 0, 0)
267      utc_year, utc_month, utc_day, utc_hour, utc_min, utc_sec = pl.btime(tai)
268      pl.configtime(scale, offset1, offset2, 0, 0, 0, 0, 0, 0, 0, 0.)
269      utc = pl.ctime(utc_year, utc_month, utc_day, utc_hour, utc_min, utc_sec)
270      y[i]=(tai-utc)*scale*86400.
271    end
272
273    pl.adv(0)
274    pl.vsta()
275    pl.wind(xmin, xmax, ymin, ymax)
276    pl.col0(1)
277    if if_TAI_time_format ~= 0 then
278      pl.configtime(scale, offset1, offset2, 0, 0, 0, 0, 0, 0, 0, 0)
279    else
280      pl.configtime(scale, offset1, offset2, 2, 0, 0, 0, 0, 0, 0, 0)
281    end
282    pl.timefmt(time_format)
283    pl.box("bcnstd", xlabel_step, 0, "bcnstv", 0., 0)
284    pl.col0(3)
285    title = "@frPLplot Example 29 - TAI-UTC " .. title_suffix
286    pl.lab(xtitle, "TAI-UTC (sec)", title)
287
288    pl.col0(4)
289
290    pl.line(x, y)
291  end
292end
293
294----------------------------------------------------------------------------
295-- main
296--
297-- Draws several plots which demonstrate the use of date / time formats for
298-- the axis labels.
299-- Time formatting is done using the system strftime routine. See the
300-- documentation of this for full details of the available formats.
301--
302-- 1) Plotting temperature over a day (using hours / minutes)
303-- 2) Plotting
304--
305-- Note: Times are stored as seconds since the epoch (usually 1st Jan 1970).
306--
307----------------------------------------------------------------------------
308
309-- Parse command line arguments
310pl.parseopts(arg, pl.PL_PARSE_FULL)
311
312-- Initialize plplot
313pl.init()
314
315-- Change the escape character to a '@' instead of the default '#'
316pl.sesc('@')
317
318plot1()
319
320plot2()
321
322plot3()
323
324plot4()
325
326-- Don't forget to call plend() to finish off!
327pl.plend()
nanonote-example-files/files/lua-plplot-examples/x30.lua
1--[[ $Id: x30.lua 10668 2009-12-02 08:38:49Z airwin $
2
3    Alpha color values demonstration.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27red = { 0, 255, 0, 0 }
28green = { 0, 0, 255, 0 }
29blue = { 0, 0, 0, 255 }
30alpha = { 1, 1, 1, 1 }
31
32px = { 0.1, 0.5, 0.5, 0.1 }
33py = { 0.1, 0.1, 0.5, 0.5 }
34
35pos = { 0, 1 }
36rcoord = { 1, 1 }
37gcoord = { 0, 0 }
38bcoord = { 0, 0 }
39acoord = { 0, 1 }
40rev = { 0, 0 }
41
42pl.parseopts (arg, pl.PL_PARSE_FULL);
43
44pl.init()
45pl.scmap0n(4)
46pl.scmap0a(red, green, blue, alpha)
47
48-- Page 1:
49--
50-- This is a series of red, green and blue rectangles overlaid
51-- on each other with gradually increasing transparency.
52
53-- Set up the window
54pl.adv(0)
55pl.vpor(0, 1, 0, 1)
56pl.wind(0, 1, 0, 1)
57pl.col0(0)
58pl.box("", 1, 0, "", 1, 0)
59
60-- Draw the boxes
61for i = 0, 8 do
62  icol = math.mod(i, 3) + 1
63
64  -- Get a color, change its transparency and
65  -- set it as the current color.
66  r, g, b, a = pl.gcol0a(icol)
67  pl.scol0a(icol, r, g, b, 1-i/9)
68  pl.col0(icol)
69
70  -- Draw the rectangle
71  pl.fill(px, py)
72
73  -- Shift the rectangles coordinates
74  for j = 1, 4 do
75    px[j] = px[j] + 0.5/9
76    py[j] = py[j] + 0.5/9
77  end
78end
79
80-- Page 2:
81
82-- This is a bunch of boxes colored red, green or blue with a single
83-- large (red) box of linearly varying transparency overlaid. The
84-- overlaid box is completely transparent at the bottom and completely
85-- opaque at the top.
86
87-- Set up the window
88pl.adv(0)
89pl.vpor(0.1, 0.9, 0.1, 0.9)
90pl.wind(0.0, 1.0, 0.0, 1.0)
91
92-- Draw the boxes. There are 25 of them drawn on a 5 x 5 grid.
93for i = 0, 4 do
94  -- Set box X position
95  px[1] = 0.05 + 0.2 * i
96  px[2] = px[1] + 0.1
97  px[3] = px[2]
98  px[4] = px[1]
99
100  -- We don't want the boxes to be transparent, so since we changed
101  -- the colors transparencies in the first example we have to change
102  -- the transparencies back to completely opaque.
103  icol = math.mod(i, 3) + 1
104  r, g, b, a = pl.gcol0a(icol)
105  pl.scol0a(icol, r, g, b, 1)
106  pl.col0(icol)
107
108  for j = 0, 4 do
109    -- Set box y position and draw the box.
110    py[1] = 0.05 + 0.2 * j
111    py[2] = py[1]
112    py[3] = py[1] + 0.1
113    py[4] = py[3]
114    pl.fill(px, py)
115  end
116end
117
118-- Create the color map with 128 colors and use plscmap1la to initialize
119-- the color values with a linearly varying red transparency (or alpha)
120pl.scmap1n(128)
121pl.scmap1la(1, pos, rcoord, gcoord, bcoord, acoord, rev)
122
123-- Use that cmap1 to create a transparent red gradient for the whole
124-- window.
125px[1] = 0.
126px[2] = 1.
127px[3] = 1.
128px[4] = 0.
129
130py[1] = 0.
131py[2] = 0.
132py[3] = 1.
133py[4] = 1.
134
135pl.gradient(px, py, 90.)
136
137pl.plend()
nanonote-example-files/files/lua-plplot-examples/x31.lua
1--[[ $Id: x31.lua 9533 2009-02-16 22:18:37Z smekal $
2
3  Copyright (C) 2008 Werner Smekal
4
5  set/get tester
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24
25-- initialise Lua bindings for PLplot examples.
26dofile("plplot_examples.lua")
27
28r1 = { 0, 255 }
29g1 = { 255, 0 }
30b1 = { 0, 0 }
31a1 = { 1, 1 }
32
33-- Parse and process command line arguments
34status = 0
35pl.parseopts(arg, pl.PL_PARSE_FULL)
36
37-- Test setting / getting familying parameters before plinit
38-- Save values set by plparseopts to be restored later.
39fam0, num0, bmax0 = pl.gfam()
40fam1 = 0
41num1 = 10
42bmax1 = 1000
43pl.sfam(fam1, num1, bmax1)
44
45-- Retrieve the same values?
46fam2, num2, bmax2 = pl.gfam()
47print(string.format("family parameters: fam, num, bmax = %d %d %d", fam2, num2, bmax2))
48if fam2~=fam1 or num2~=num1 or bmax2~=bmax1 then
49  io.stderr:write("plgfam test failed\n")
50  status = 1
51end
52-- Restore values set initially by plparseopts.
53pl.sfam(fam0, num0, bmax0)
54
55-- Test setting / getting page parameters before plinit
56-- Save values set by plparseopts to be restored later.
57xp0, yp0, xleng0, yleng0, xoff0, yoff0 = pl.gpage()
58xp1 = 200.
59yp1 = 200.
60xleng1 = 400
61yleng1 = 200
62xoff1 = 10
63yoff1 = 20
64pl.spage(xp1, yp1, xleng1, yleng1, xoff1, yoff1)
65
66-- Retrieve the same values?
67xp2, yp2, xleng2, yleng2, xoff2, yoff2 = pl.gpage()
68print(string.format("page parameters: xp, yp, xleng, yleng, xoff, yoff = %f %f %d %d %d %d", xp2, yp2, xleng2, yleng2, xoff2, yoff2))
69if xp2~=xp1 or yp2~=yp1 or xleng2~=xleng1 or yleng2~=yleng1 or xoff2~=xoff1 or yoff2~=yoff1 then
70  io.stderr:write("plgpage test failed\n")
71  status = 1
72end
73-- Restore values set initially by plparseopts.
74pl.spage(xp0, yp0, xleng0, yleng0, xoff0, yoff0)
75
76-- Test setting / getting compression parameter across plinit.
77compression1 = 95
78pl.scompression(compression1)
79
80-- Initialize plplot
81pl.init()
82
83-- Test if device initialization screwed around with the preset
84-- compression parameter.
85compression2 = pl.gcompression()
86print("Output various PLplot parameters")
87print("compression parameter = " .. compression2)
88if compression2~=compression1 then
89  io.stderr:write("plgcompression test failed\n")
90  status = 1
91end
92
93
94-- Exercise plscolor, plscol0, plscmap1, and plscmap1a to make sure
95--they work without any obvious error messages.
96pl.scolor(1)
97pl.scol0(1, 255, 0, 0)
98pl.scmap1(r1, g1, b1)
99pl.scmap1a(r1, g1, b1, a1)
100
101level2 = pl.glevel()
102print("level parameter = " .. level2)
103if level2~=1 then
104  io.stderr:write("plglevel test failed.\n")
105  status = 1
106end
107
108pl.adv(0)
109pl.vpor(0.01, 0.99, 0.02, 0.49)
110xmin, xmax, ymin, ymax = pl.gvpd()
111print(string.format("plvpor: xmin, xmax, ymin, ymax = %f %f %f %f", xmin, xmax, ymin, ymax))
112if xmin~=0.01 or xmax~=0.99 or ymin~=0.02 or ymax~=0.49 then
113  io.stderr:write("plgvpd test failed\n")
114  status = 1
115end
116xmid = 0.5*(xmin+xmax)
117ymid = 0.5*(ymin+ymax)
118
119pl.wind(0.2, 0.3, 0.4, 0.5)
120xmin, xmax, ymin, ymax = pl.gvpw()
121print(string.format("plwind: xmin, xmax, ymin, ymax = %f %f %f %f", xmin, xmax, ymin, ymax))
122if xmin~=0.2 or xmax~=0.3 or ymin~=0.4 or ymax~=0.5 then
123  io.stderr:write("plgvpw test failed\n")
124  status = 1
125end
126
127-- Get world coordinates for middle of viewport
128wx, wy, win = pl.calc_world(xmid,ymid)
129print(string.format("world parameters: wx, wy, win = %f %f %d", wx, wy, win))
130if math.abs(wx-0.5*(xmin+xmax))>1.0e-5 or math.abs(wy-0.5*(ymin+ymax))>1.0e-5 then
131  io.stderr:write("plcalc_world test failed\n")
132  status = 1
133end
134
135-- Retrieve and print the name of the output file (if any).
136-- This goes to stderr not stdout since it will vary between tests and
137-- we want stdout to be identical for compare test.
138fnam = pl.gfnam()
139if fnam=="" then
140  print("No output file name is set")
141else
142  print("Output file name read")
143end
144io.stderr:write(string.format("Output file name is %s\n",fnam))
145
146-- Set and get the number of digits used to display axis labels
147-- Note digits is currently ignored in pls[xyz]ax and
148-- therefore it does not make sense to test the returned
149-- value
150pl.sxax(3,0)
151digmax, digits = pl.gxax()
152print(string.format("x axis parameters: digmax, digits = %d %d", digmax, digits))
153if digmax~=3 then
154  io.stderr:write("plgxax test failed\n")
155  status = 1
156end
157
158pl.syax(4,0)
159digmax, digits = pl.gyax()
160print(string.format("y axis parameters: digmax, digits = %d %d", digmax, digits))
161if digmax~=4 then
162  io.stderr:write("plgyax test failed\n")
163  status = 1
164end
165
166pl.szax(5,0)
167digmax,digits = pl.gzax()
168print(string.format("z axis parameters: digmax, digits = %d %d", digmax, digits))
169if digmax~=5 then
170  io.stderr:write("plgzax test failed\n")
171  status = 1
172end
173
174pl.sdidev(0.05, pl.PL_NOTSET, 0.1, 0.2)
175mar, aspect, jx, jy = pl.gdidev()
176print(string.format("device-space window parameters: mar, aspect, jx, jy = %f %f %f %f" , mar, aspect, jx, jy))
177if mar~=0.05 or jx~=0.1 or jy~=0.2 then
178  io.stderr:write("plgdidev test failed\n")
179  status = 1
180end
181
182pl.sdiori(1.0)
183ori = pl.gdiori()
184print(string.format("ori parameter = %f", ori))
185if ori~=1.0 then
186  io.stderr:write("plgdiori test failed\n")
187  status = 1
188end
189
190pl.sdiplt(0.1, 0.2, 0.9, 0.8)
191xmin, ymin, xmax, ymax = pl.gdiplt()
192print(string.format("plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f", xmin, ymin, xmax, ymax))
193if xmin~=0.1 or xmax~=0.9 or ymin~=0.2 or ymax~=0.8 then
194  io.stderr:write("plgdiplt test failed\n")
195  status = 1
196end
197
198pl.sdiplz(0.1, 0.1, 0.9, 0.9)
199zxmin, zymin, zxmax, zymax = pl.gdiplt()
200print(string.format("zoomed plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f", zxmin, zymin, zxmax, zymax))
201if math.abs(zxmin -(xmin + (xmax-xmin)*0.1)) > 1.0e-5 or
202   math.abs(zxmax -(xmin+(xmax-xmin)*0.9)) > 1.0e-5 or
203   math.abs(zymin -(ymin+(ymax-ymin)*0.1)) > 1.0e-5 or
204   math.abs(zymax -(ymin+(ymax-ymin)*0.9)) > 1.0e-5 then
205  io.stderr:write("plsdiplz test failed\n")
206  status = 1
207end
208
209pl.scolbg(10, 20, 30)
210r, g, b = pl.gcolbg()
211print(string.format("background colour parameters: r, g, b = %d %d %d", r, g, b))
212if r~=10 or g~=20 or b~=30 then
213  io.stderr:write("plgcolbg test failed\n")
214  status = 1
215end
216
217pl.scolbga(20, 30, 40, 0.5)
218r, g, b, a = pl.gcolbga()
219print(string.format("background/transparency colour parameters: r, g, b, a = %d %d %d %f", r, g, b, a))
220if r~=20 or g~=30 or b~=40 or a~=0.5 then
221  io.stderr:write("plgcolbga test failed\n")
222  status = 1
223end
224
225pl.plend()

Archive Download the corresponding diff file



interactive