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