Root/nanonote-example-files/example-files/data/Examples/lua-plplot-examples/x17.lua

Source at commit a08dac6 created 13 years 1 month ago.
By Xiangfu Liu, nanonote-example-files, install to data, prepare for add script-files
1--[[ $Id: x17.lua 9526 2009-02-13 22:06:13Z smekal $
2
3    Plots a simple stripchart with four pens.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24
25-- initialise Lua bindings for PLplot examples.
26dofile("plplot_examples.lua")
27
28
29--------------------------------------------------------------------------
30-- main
31--------------------------------------------------------------------------
32
33nsteps = 1000
34colline = {}
35legline = {}
36
37-- plplot initialization
38-- Parse and process command line arguments
39pl.parseopts(arg, pl.PL_PARSE_FULL)
40
41-- User sets up plot completely except for window and data
42-- Eventually settings in place when strip chart is created will be
43-- remembered so that multiple strip charts can be used simultaneously.
44 
45-- Specify some reasonable defaults for ymin and ymax
46-- The plot will grow automatically if needed (but not shrink)
47ymin = -0.1
48ymax = 0.1
49
50-- Specify initial tmin and tmax -- this determines length of window.
51-- Also specify maximum jump in t
52-- This can accomodate adaptive timesteps
53tmin = 0
54tmax = 10
55tjump = 0.3 -- percentage of plot to jump
56
57-- Axes options same as plbox.
58-- Only automatic tick generation and label placement allowed
59-- Eventually I'll make this fancier
60colbox = 1
61collab = 3
62styline = { 2, 3, 4, 5 } -- line style
63colline = { 2, 3, 4, 5 } -- pens color
64
65legline= { "sum", "sin", "sin*noi", "sin+noi" } -- pens legend
66
67xlab = 0 -- legend position
68ylab = 0.25
69
70autoy = 1 -- autoscale y
71acc = 1 -- don't scrip, accumulate
72
73-- Initialize plplot
74pl.init()
75
76pl.adv(0)
77pl.vsta()
78
79id1 = pl.stripc("bcnst", "bcnstv",
80   tmin, tmax, tjump, ymin, ymax,
81   xlab, ylab,
82   autoy, acc,
83   colbox, collab,
84   colline, styline, legline,
85   "t", "", "Strip chart demo")
86
87autoy = 0 -- autoscale y
88acc = 1 -- accumulate
89
90-- This is to represent a loop over time
91-- Let's try a random walk process
92
93y1 = 0
94y2 = 0
95y3 = 0
96y4 = 0
97dt = 0.1
98
99for n = 0, nsteps-1 do
100    for i = 0, 200000 do end
101    t = n * dt
102    noise = pl.randd() - 0.5
103    y1 = y1 + noise
104    y2 = math.sin(t*math.pi/18)
105    y3 = y2 * noise
106    y4 = y2 + noise/3
107
108  -- There is no need for all pens to have the same number of
109  -- points or beeing equally time spaced.
110    if math.mod(n, 2)~=0 then pl.stripa(id1, 0, t, y1) end
111    if math.mod(n, 3)~=0 then pl.stripa(id1, 1, t, y2) end
112    if math.mod(n, 4)~=0 then pl.stripa(id1, 2, t, y3) end
113    if math.mod(n, 5)~=0 then pl.stripa(id1, 3, t, y4) end
114end
115
116-- Destroy strip chart and it's memory
117pl.stripd(id1)
118pl.plend()
119

Archive Download this file



interactive