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

1--[[ $Id: x11.lua 9533 2009-02-16 22:18:37Z smekal $
2
3    Mesh plot demo.
4
5  Copyright (C) 2008 Werner Smekal
6
7  This file is part of PLplot.
8
9  PLplot is free software you can redistribute it and/or modify
10  it under the terms of the GNU General Library Public License as published
11  by the Free Software Foundation either version 2 of the License, or
12  (at your option) any later version.
13
14  PLplot is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Library General Public License for more details.
18
19  You should have received a copy of the GNU Library General Public License
20  along with PLplot if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22--]]
23
24-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27XPTS = 35 -- Data points in x
28YPTS = 46 -- Data points in y
29LEVELS = 10
30
31opt = { pl.DRAW_LINEXY, pl.DRAW_LINEXY }
32
33alt = { 33, 17 }
34az = { 24, 115 }
35
36title = {
37    "#frPLplot Example 11 - Alt=33, Az=24, Opt=3",
38    "#frPLplot Example 11 - Alt=17, Az=115, Opt=3" }
39
40
41-- bitwise or operator from http://lua-users.org/wiki/BaseSixtyFour
42-- (c) 2006-2008 by Alex Kloss
43-- licensed under the terms of the LGPL2
44
45-- return single bit (for OR)
46function bit(x,b)
47    return (math.mod(x, 2^b) - math.mod(x,2^(b-1)) > 0)
48end
49
50-- logic OR for number values
51function lor(x,y)
52    result = 0
53    for p=1,8 do result = result + (((bit(x,p) or bit(y,p)) == true) and 2^(p-1) or 0) end
54    return result
55end
56
57    
58function cmap1_init()
59  i = { 0, 1 } -- left boundary , right boundary
60  h = { 240, 0 } -- blue -> green -> yellow -> red
61  l = { 0.6, 0.6 }
62  s = { 0.8, 0.8 }
63
64  pl.scmap1n(256)
65  pl.scmap1l(0, i, h, l, s)
66end
67
68
69----------------------------------------------------------------------------
70-- main
71--
72-- Does a series of mesh plots for a given data set, with different
73-- viewing options in each plot.
74----------------------------------------------------------------------------
75
76nlevel = LEVELS
77clevel = {}
78
79-- Parse and process command line arguments
80pl.parseopts(arg, pl.PL_PARSE_FULL)
81
82-- Initialize plplot
83pl.init()
84
85x = {}
86y = {}
87z = {}
88
89for i=1, XPTS do
90  x[i] = 3 * (i-1-math.floor(XPTS/2)) / math.floor(XPTS/2)
91end
92
93for i=1, YPTS do
94  y[i] = 3 * (i-1-math.floor(YPTS/2)) / math.floor(YPTS/2)
95end
96
97for i=1, XPTS do
98  xx = x[i]
99  z[i] = {}
100  for j=1, YPTS do
101    yy = y[j]
102    z[i][j] = 3 * (1-xx)^2 * math.exp(-xx^2 - (yy+1.)^2) -
103              10 * (xx/5 - xx^3 - yy^5) * math.exp(-xx^2-yy^2) -
104              1/3 * math.exp(-(xx+1)^2 - yy^2)
105   
106    -- Jungfraujoch/Interlaken
107    if false then
108      if z[i][j] < -1 then z[i][j] = -1 end
109    end
110  end
111end
112
113zmax, zmin = pl.MinMax2dGrid(z)
114step = (zmax - zmin)/(nlevel+1)
115for i=1, nlevel do
116  clevel[i] = zmin + step + step*(i-1)
117end
118
119cmap1_init()
120for k=1, 2 do
121  for i=1, 4 do
122    pl.adv(0)
123    pl.col0(1)
124    pl.vpor(0, 1, 0, 0.9)
125    pl.wind(-1, 1, -1, 1.5)
126    pl.w3d(1, 1, 1.2, -3, 3, -3, 3, zmin, zmax, alt[k], az[k])
127    pl.box3("bnstu", "x axis", 0, 0,
128            "bnstu", "y axis", 0, 0,
129            "bcdmnstuv", "z axis", 0, 4)
130
131    pl.col0(2)
132
133    -- wireframe plot
134    if i==1 then
135      pl.mesh(x, y, z, opt[k])
136    end
137
138    -- magnitude colored wireframe plot
139    if i==2 then
140      pl.mesh(x, y, z, lor(opt[k], pl.MAG_COLOR))
141    end
142
143    -- magnitude colored wireframe plot with sides
144    if i==3 then
145      pl.plot3d(x, y, z, lor(opt[k], pl.MAG_COLOR), 1)
146    end
147
148    -- magnitude colored wireframe plot with base contour
149    if i==4 then
150      pl.meshc(x, y, z, lor(lor(opt[k], pl.MAG_COLOR), pl.BASE_CONT), clevel)
151    end
152
153    pl.col0(3)
154    pl.mtex("t", 1, 0.5, 0.5, title[k])
155  end
156end
157
158-- Clean up
159  
160pl.plend()
161

Archive Download this file



interactive