1
## Copyright (C) 1998-2003 Joao Cardoso.
2
## Copyright (C) 2004 Rafael Laboissiere
4
## This program is free software; you can redistribute it and/or modify it
5
## under the terms of the GNU General Public License as published by the
6
## Free Software Foundation; either version 2 of the License, or (at your
7
## option) any later version.
9
## This program is distributed in the hope that it will be useful, but
10
## WITHOUT ANY WARRANTY; without even the implied warranty of
11
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
## General Public License for more details.
14
## This file is part of plplot_octave.
16
## shade(x, y, z [, levels [, contour] )
17
## shade(z [, levels [, contour] )
19
## plot shade of matrix z versus vectors x,y.
20
## level can be a scalar speficying the number of shade levels,
21
## or a vector, specifying where the shade level must be
22
## if contour exists, each shade level will be contoured with 'countour' color
24
function shade(x, y, z, levels, cont )
31
old_empty_list_elements_ok = warning("query", "Octave:empty-list-elements");
32
warning("off","Octave:empty-list-elements");
34
if (nargin == 1 && ismatrix(x))
37
z = x; y = 1:rows(z); x = 1:columns(z);
38
elseif (nargin == 2 && ismatrix(x))
40
z = x; y = 1:rows(z); x = 1:columns(z);
41
elseif (nargin == 3 && isscalar(z))
43
z = x; y = 1:rows(z); x = 1:columns(z);
51
if (isscalar(levels) && levels == 1) # segmentation violation!
55
if (rows(x) > 1 & columns(x) > 1 & rows(y) > 1 & columns(y) > 1)
61
## plot color and pen width of boundary of shade region
63
max_color = 0; max_width = 0;
66
cont_color = cont; cont_width = 1;
68
cont_color = 0; cont_width = 0;
72
xmm = xm = min(min(x)); xM = max(max(x));
73
ymm = ym = min(min(y)); yM = max(max(y));
74
zm = min(min(z)); zM = max(max(z));
76
if (__pl.axis_st(strm))
77
xm = __pl.axis(strm,1); xM = __pl.axis(strm,2);
79
ix = find(x >= xm & x <= xM);
84
if (length(__pl.axis(strm,:)) >= 4)
85
ym = __pl.axis(strm,3); yM = __pl.axis(strm,4);
87
iy = find(y >= ym & y <= yM);
92
__pl.axis(strm,3) = ym; __pl.axis(strm,4) = yM;
94
if (length(__pl.axis(strm,:)) == 6)
95
zm = __pl.axis(strm,5); zM = __pl.axis(strm,6);
97
__pl.axis(strm,5) = zm; __pl.axis(strm,6) = zM;
99
else # make axis() return current axis
100
__pl.axis(strm,1) = xm; __pl.axis(strm,2) = xM;
101
__pl.axis(strm,3) = ym; __pl.axis(strm,4) = yM;
102
__pl.axis(strm,5) = zm; __pl.axis(strm,6) = zM;
105
__pl.plcol(strm) = 1;
106
plcol0(15);pllsty(1);
107
__pl_plenv(xm, xM, ym, yM, 0, -2);
109
if (columns(__pl.axis(strm,:)) != 6)
110
error("You must contour/shade plot something before entering hold mode");
112
xmm = xm = __pl.axis(strm,1); xM = __pl.axis(strm,2);
113
ymm = ym = __pl.axis(strm,3); yM = __pl.axis(strm,4);
114
zm = __pl.axis(strm,5); zM = __pl.axis(strm,6);
116
ix = find(x >= xm & x <= xM);
117
iy = find(y >= ym & y <= yM);
124
maxx = max(max(x)); maxy = max(max(y)); minx = min(min(x)); miny = min(min(y));
125
if (columns(x)>1 & rows(x) == 1)
128
if (columns(y)>1 & rows(y) == 1)
132
if (!isscalar(levels))
133
n = length(levels)-1;
138
clevel = linspace(zm, zM, levels+1);
139
cclevel = linspace(zm, zM, levels);
142
__pl.type(strm) = -2;
144
__pl.plcol(strm) = 1;
145
__pl.pllsty(strm) = 1;
146
__pl.lab_pos(strm) = 1;
149
if (0) ## plshades() is slower than several calls to plshade() !? and plshades() sometimes fails ?!
151
plshade1(z', 0, minx, maxx, miny, maxy,
152
clevel(i), clevel(i+1),
154
cont_color, cont_width, max_color, max_width, 1, x, y);
157
if (columns(x) == 1 & columns(y) == 1)
158
plshades1(z', minx, maxx, miny, maxy,
159
clevel', 1, cont_color, cont_width, 1, x, y);
161
plshades2(z', minx, maxx, miny, maxy,
162
clevel', 1, cont_color, cont_width, 1, x', y');
167
__pl.lab_str = [__pl.lab_str; sprintf("%#+.2G", cclevel(i))];
168
__pl.lab_col(strm,__pl.lab_pos(strm)) = __pl.plcol(strm);
169
__pl.lab_lsty(strm,__pl.lab_pos(strm)) = __pl.pllsty(strm);
170
__pl.lab_pos(strm) = __pl.lab_pos(strm) + 1;
171
__pl.plcol(strm) = rem(__pl.plcol(strm), 15)+1;
172
if (__pl.line_style(strm))
173
__pl.pllsty(strm) = rem(__pl.pllsty(strm), 8)+1;
177
if (__pl.grid(strm)) # this has to be done after shading
179
plbox("bcnsgt",0,0,"bcnsgtv",0,0)
182
plbox("bcnst",0,0,"bcnstv",0,0)
185
if (__pl.legend(strm))
190
pllab(tdeblank(__pl.xlabel(strm,:)), tdeblank(__pl.ylabel(strm,:)), tdeblank(__pl.tlabel(strm,:)));
193
__pl.items(strm) = 1; # for now!
195
unwind_protect_cleanup
197
warning(old_empty_list_elements_ok.state, "Octave:empty-list-elements");