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