3
# Demo x15 for the PLplot PDL binding
7
# Copyright (C) 2004 Rafael Laboissiere
9
# This file is part of PLplot.
11
# PLplot is free software; you can redistribute it and/or modify
12
# it under the terms of the GNU Library General Public License as published
13
# by the Free Software Foundation; either version 2 of the License, or
14
# (at your option) any later version.
16
# PLplot is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU Library General Public License for more details.
21
# You should have received a copy of the GNU Library General Public License
22
# along with PLplot; if not, write to the Free Software
23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28
use PDL::Graphics::PLplot;
30
use constant XPTS => 35; # Data points in x
31
use constant YPTS => 46; # Data points in y
33
$z = zeroes (XPTS, YPTS);
46
# Does a variety of shade plots
50
# Parse and process command line arguments
52
plParseOpts (\@ARGV, PL_PARSE_SKIP | PL_PARSE_NOPROGRAM);
70
my $xx = (sequence (XPTS) - int(XPTS / 2)) / int(XPTS / 2);
71
my $yy = (sequence (YPTS) - int(YPTS / 2)) / int(YPTS / 2) - 1.0;
72
for (my $i = 0; $i < XPTS; $i++) {
73
my $xi = $xx->index ($i);
74
for (my $j = 0; $j < YPTS; $j++) {
75
my $yi = $yy->index ($j);
76
$z->slice ("$i,$j") .= $xi ** 2 - $yi ** 2
77
+ ($xi - $yi) / ($xi * $xi + $yi ** 2 + 0.1);
81
($zmin, $zmax) = f2mnmx ($z);
93
# Initializes color map 1 in HLS space
96
my $i = pdl [0, # left boundary
97
0.45, # just before center
98
0.55, # just after center
101
my $h = pdl [260, # hue -- low: blue-violet
102
260, # only change as we go over vertex
103
20, # hue -- high: red
108
$l = pdl [0.5, # lightness -- low
109
0.0, # lightness -- center
110
0.0, # lightness -- center
111
0.5]; # lightness -- high
113
plscolbg (255, 255, 255);
114
$l = pdl [0.5, # lightness -- low
115
1.0, # lightness -- center
116
1.0, # lightness -- center
117
0.5]; # lightness -- high
119
my $s = pdl [1, # maximum saturation
120
1, # maximum saturation
121
1, # maximum saturation
122
1]; # maximum saturation
124
plscmap1l (0, $i, $h, $l, $s, pdl ([]));
129
# Initializes color map 1 in HLS space
132
my $i = pdl [0, # left boundary
133
0.45, # just before center
134
0.55, # just after center
137
my $h = pdl [260, # hue -- low: blue-violet
138
260, # only change as we go over vertex
139
20, # hue -- high: red
144
$l = pdl [0.6, # lightness -- low
145
0.0, # lightness -- center
146
0.0, # lightness -- center
147
0.6]; # lightness -- high
149
plscolbg (255, 255, 255);
150
$l = pdl [0.5, # lightness -- low
151
1.0, # lightness -- center
152
1.0, # lightness -- center
153
0.5]; # lightness -- high
155
my $s = pdl [1, # maximum saturation
156
0.5, # maximum saturation
157
0.5, # maximum saturation
158
1]; # maximum saturation
160
plscmap1l (0, $i, $h, $l, $s, pdl ([]));
165
# Illustrates a single shaded region
175
plvpor (0.1, 0.9, 0.1, 0.9);
176
plwind (-1.0, 1.0, -1.0, 1.0);
178
# Plot using identity transform
180
my $shade_min = $zmin + ($zmax - $zmin) * 0.4;
181
my $shade_max = $zmin + ($zmax - $zmin) * 0.6;
190
plshade1 ($z, -1, 1, -1, 1,
191
$shade_min, $shade_max, $sh_cmap, $sh_color, $sh_width,
192
$min_color, $min_width, $max_color, $max_width,
196
plbox (0.0, 0, 0.0, 0, "bcnst", "bcnstv");
198
pllab ("distance", "altitude", "Bogon flux");
203
# Illustrates multiple adjacent shaded regions, using different fill
204
# patterns for each region
208
my $nlin = pdl [1, 1, 1, 1, 1, 2, 2, 2, 2, 2];
209
my $inc = pdl [ [450, 0], [-450, 0], [0, 0], [900, 0],
210
[300, 0], [450,-450], [0, 900], [0, 450],
211
[450, -450], [0, 900] ];
212
my $spa = pdl [ [2000, 2000], [2000, 2000], [2000, 2000],
213
[2000, 2000], [2000, 2000], [2000, 2000],
214
[2000, 2000], [2000, 2000], [4000, 4000],
225
plvpor (0.1, 0.9, 0.1, 0.9);
226
plwind (-1.0, 1.0, -1.0, 1.0);
228
# Plot using identity transform
230
for (my $i = 0; $i < 10; $i++) {
231
my $shade_min = $zmin + ($zmax - $zmin) * $i / 10.0;
232
my $shade_max = $zmin + ($zmax - $zmin) * ($i + 1) / 10.0;
233
my $sh_color = $i + 6;
234
my $n = $nlin->slice("($i)");
236
plpat ($n, $inc->slice("0:$nm1,($i)"), $spa->slice("0:$nm1,($i)"));
238
plshade1 ($z, -1, 1, -1, 1,
239
$shade_min, $shade_max, $sh_cmap, $sh_color, $sh_width,
240
$min_color, $min_width, $max_color, $max_width,
245
plbox (0.0, 0, 0.0, 0, "bcnst", "bcnstv");
247
pllab ("distance", "altitude", "Bogon flux");
252
# Illustrates shaded regions in 3d, using a different fill pattern for
257
my $xx = pdl [ [-1.0, 1.0, 1.0, -1.0, -1.0],
258
[-1.0, 1.0, 1.0, -1.0, -1.0] ];
259
my $yy = pdl [ [1.0, 1.0, 0.0, 0.0, 1.0],
260
[-1.0, -1.0, 0.0, 0.0, -1.0] ];
261
my $zz = pdl [ [0.0, 0.0, 1.0, 1.0, 0.0],
262
[0.0, 0.0, 1.0, 1.0, 0.0] ];
265
plvpor (0.1, 0.9, 0.1, 0.9);
266
plwind (-1.0, 1.0, -1.0, 1.0);
267
plw3d (1., 1., 1., -1.0, 1.0, -1.0, 1.0, 0.0, 1.5, 30., -40,);
269
# Plot using identity transform
272
plbox3 (0.0, 0, 0.0, 0, 0.5, 0, "bntu", "X", "bntu", "Y", "bcdfntu", "Z");
274
pllab ("","","3-d polygon filling");
278
plline3 ($xx->slice(":,0"), $yy->slice(":,0"), $zz->slice(":,0"));
279
plfill3 (4, $xx->slice("0:4,0"), $yy->slice("0:4,0"), $zz->slice("0:4,0"));
281
plline3 ($xx->slice(":,1"), $yy->slice(":,1"), $zz->slice(":,1"));
282
plfill3 (4, $xx->slice("0:4,1"), $yy->slice("0:4,1"), $zz->slice("0:4,1"));
288
# Returns min & max of input 2d array
292
return (min ($f), max ($f));