"Matlab-like" plotting library

"Matlab-like" plotting library Commit Details

Date:2018-02-27 13:12:19 (9 months 19 days ago)
Author:Stéphane Mottelet
Commit:77
Parents: 76
Message:first stuff for 6.x porting. New .sci files
Changes:
A/trunk/plotlib/macros/scilab_gcf.sci
A/trunk/plotlib/macros/scilab_surf.sci
A/trunk/plotlib/macros/%axesData_i_h.sci
A/trunk/plotlib/macros/scilab_colorbar.sci
A/trunk/plotlib/macros/%leafData_i_h.sci
A/trunk/plotlib/macros/scilab_subplot.sci
A/trunk/plotlib/macros/scilab_gca.sci
A/trunk/plotlib/macros/scilab_mesh.sci
A/trunk/plotlib/macros/%figureDa_i_h.sci
A/trunk/plotlib/macros/scilab_legend.sci
A/trunk/plotlib/macros/scilab_plot.sci

File differences

trunk/plotlib/macros/%leafData_i_h.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
//
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function h=generic_i_h(i,v,h)
hsave=h
// if v==[] then error('Field property cannot be []'),end
if type(i)==10 then set(h,i,v),return,end
if type(i)<>15 then error(msprintf(_("%s: Wrong type for input argument #%d.\n"),"generic_i_h",1)),end
if and(type(i($))<>[1 2 4 8 129 15]) then
i($+1)=:
end
n = size(i)
hdl=h;hind=[]
for k=1:size(i)// walk down in the handle tree
p=i(k)
lasthandle=hdl,
if type(p)==10 then
hdl=get(hdl,p),
elseif or(type(p)==[1 2 4 8 129]) then
hdl=hdl(p)
elseif type(p)==15 then
hdl=hdl(p(:))
else
error("Invalid path")
end
if type(hdl)<>9 then //a leaf found
property=hdl
hdl=lasthandle
hind=p
if (k+1)==size(i) then
index=i($)
else
index=list(i(k+1:$))
end
break
end
end
if hind<>[] then // a property found
if type(index)==15 & and(type(property)<>[15 16 17]) then
property(index(:))=v
else
if or(size(index)<>[-1 -1]) then
if (index(1)=="locations" | index(1)=="labels") & size(v,"*") ~= 1 & size(property(index),"*") ~= size(v,"*") then
error(msprintf(_("%s: Incompatible sizes for properties ''%s'' and ''%s'': Same sizes expected.\n"), "generic_i_h", string(i($-2))+".locations", string(i($-2))+".labels"));
end
property(index)=v
else
property=v
end
end
if size(hdl,"*")==1 then //a single handle
hdl(hind)=property
else //mutiple handle
np=size(hdl,"*")
for k=1:np
h=hdl(k);h(hind)=property
end
end
else
error(msprintf(_("%s: Wrong type for input argument #%d.\n"),"generic_i_h",1));
end
h = hsave
endfunction
trunk/plotlib/macros/scilab_legend.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2007-2010 - INRIA - Serge Steer <serge.steer@inria.fr>
// Copyright (C) 2017 - Samuel GOUGEON
//
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function c=scilab_legend(varargin)
if size(varargin)<1 then
error(msprintf(gettext("%s: Wrong number of input argument(s): At least %d expected.\n"), "legend", 1));
end
options_names=["in_upper_right";"in_upper_left";"in_lower_left";
"in_lower_right";"by_coordinates";"out_upper_right";
"out_upper_left";"out_lower_left";"out_lower_right";
"upper_caption";"lower_caption"];
options_codes=[1;2;3;
4;5;-1;
-2;-3;-4;
-5;-6];
f = gcf();
vis = f.immediate_drawing;
vis_on = vis == "on"; // current figure draw status (to decide if drawnow or standby)
narg = size(varargin);
k0 = 1;
H = [];
leg = [];
Acur = gca();
A = Acur;
kopt = 1;
with_box = %T;
coords=[];
if type(varargin(narg))==4 then
with_box=varargin(narg)
narg=narg-1
end
if type(varargin(narg))==1 then
pos=varargin(narg)
if size(pos,"*")==2 then //position given by coordinates
coords=pos;
narg=narg-1
elseif size(pos,"*")==1 then //position given by code
if or(pos==options_codes) then
kopt=find(pos==options_codes)
narg=narg-1
else
error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
"legend",narg,strcat(string(options_codes),",")));
end
else
error(msprintf(_("%s: Wrong size for input argument #%d."),"legend",narg));
end
elseif type(varargin(narg))==10 then
k=find(varargin(narg)==options_names)
if ~isempty(k) then
kopt=k
narg=narg-1
end
end
while type(varargin(k0))==9 then //a handle that could be an Axes, Agreg. or Polyline handle.
tmpH=varargin(k0)
if tmpH.type=="Axes" then
A = tmpH;
end
tmpH=tmpH($:-1:1);
H=[getvalidchildren(tmpH);H];
k0 = k0+1;
end
if H==[] then
//walk subtree to get all proper children
H=getvalidchildren(A)
end
if H==[] then
error(msprintf(_("%s: No ''%s'' handle found.\n"), "legend","Polyline"));
end
//get all labels
for k=k0:narg
if type(varargin(k))<>10 then
break;
end
vk=varargin(k)
leg=[leg; vk(:)]
end
nleg=size(leg,"*")
//upper left coordinates
if ~isempty(coords) then
bnds=get(gca(),"axes_bounds");
as=get(gcf(),"axes_size");
[x1,y1,rect]=xchange(coords(1),coords(2),"f2i")
x1=x1-as(1)*bnds(1)
y1=y1-as(2)*bnds(2)
pos=[x1/(as(1)*bnds(3)), y1/(as(2)*bnds(4))]
kopt=5
elseif kopt==5 then
pos=[]
end
// the number of labels might be lower than the number of polylines
nbLeg = min(size(H, "*"), size(leg, "*"));
first_handle=size(H, "*")-nbLeg+1;
H = H(first_handle:size(H, "*"));
leg = leg(1:nbLeg);
drawlater()
c=captions(H,leg)
if options_codes(kopt)<0 then
c.background=f.background
else
c.background=Acur.background
end
if with_box then c.line_mode="on",else c.line_mode="off",end
c.legend_location=options_names(kopt)
if kopt==5 then
if pos<>[] then
c.position=pos;
else
if vis_on then drawnow(); end // draw if figure status allows it (otherwise standby)
bnds=get(gca(),"axes_bounds");
as = get(gcf(),"axes_size");
tmp = c.parent.parent // Figure | uicontrol (frame)
if tmp.type=="uicontrol" // frame
asf = tmp.position(3:4)
if tmp.units=="normalized"
as = as .* asf
else
// pixels ('points' not implemented: scale point/pixel unknown)
as = asf
end
end
while %t
rep=xgetmouse()
if rep(3)<> -1 then break,end
[x1,y1,rect]=xchange(rep(1),rep(2),"f2i")
x1=x1-as(1)*bnds(1)
y1=y1-as(2)*bnds(2)
pos=[x1/(as(1)*bnds(3)), y1/(as(2)*bnds(4))]
c.position=pos;
end
end
end
if vis_on then drawnow(); end // draw if figure status allows it (otherwise standbye)
endfunction
function h=getvalidchildren(A)
h=[]
for k=1:size(A,"*")
a=A(k)
select a.type
case "Polyline" then
h=[h;a]
case "Axes"
ax=a.children
h=[h;getvalidchildren(ax)]
case "Compound"
for i=1:1:size(a.children,"*")
h=[h;getvalidchildren(a.children(i))]
end
end
end
endfunction
trunk/plotlib/macros/%figureDa_i_h.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
//
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function h=%figureDa_i_h(i,v,h)
hsave=h
// if v==[] then error('Field property cannot be []'),end
if type(i)==10 then set(h,i,v),return,end
if type(i)<>15 then error(msprintf(_("%s: Wrong type for input argument #%d.\n"),"generic_i_h",1)),end
if and(type(i($))<>[1 2 4 8 129 15]) then
i($+1)=:
end
n = size(i)
hdl=h;hind=[]
for k=1:size(i)// walk down in the handle tree
p=i(k)
lasthandle=hdl,
if type(p)==10 then
hdl=get(hdl,p),
elseif or(type(p)==[1 2 4 8 129]) then
hdl=hdl(p)
elseif type(p)==15 then
hdl=hdl(p(:))
else
error("Invalid path")
end
if type(hdl)<>9 then //a leaf found
property=hdl
hdl=lasthandle
hind=p
if (k+1)==size(i) then
index=i($)
else
index=list(i(k+1:$))
end
break
end
end
if hind<>[] then // a property found
if type(index)==15 & and(type(property)<>[15 16 17]) then
property(index(:))=v
else
if or(size(index)<>[-1 -1]) then
if (index(1)=="locations" | index(1)=="labels") & size(v,"*") ~= 1 & size(property(index),"*") ~= size(v,"*") then
error(msprintf(_("%s: Incompatible sizes for properties ''%s'' and ''%s'': Same sizes expected.\n"), "generic_i_h", string(i($-2))+".locations", string(i($-2))+".labels"));
end
property(index)=v
else
property=v
end
end
if size(hdl,"*")==1 then //a single handle
hdl(hind)=property
else //mutiple handle
np=size(hdl,"*")
for k=1:np
h=hdl(k);h(hind)=property
end
end
else
error(msprintf(_("%s: Wrong type for input argument #%d.\n"),"generic_i_h",1));
end
h = hsave
endfunction
trunk/plotlib/macros/scilab_colorbar.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) Bruno Pincon
// Copyright (C) Serge Steer (adaptation to new graphic system)
// Copyright (C) 2017 - Samuel GOUGEON : http://bugzilla.scilab.org/14711
//
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function scilab_colorbar(umin, umax, colminmax, fmt)
// PURPOSE
// Draw a colorbar for a plot3d, fec, Sgrayplot, etc...
//
// PARAMETERS
// umin : min value of the plot
// umax : max value of the plot
// colminmax : (optional) a vector with 2 integer components
// the first is the color number (of the current
// colormap) associated with umin
// the second the max color number ....
// default : [1 nb_colors] where nb_colors is
// the number of colors of the current colormap.
// May be useful to deal with a part of the colormap
// (for instance using fec or plot3d)
// fmt : optional, a C format to display colorbar graduations
//
// CAUTION
// this function may be used BEFORE a plot3d, fec, Sgrayplot, ...
// It is important because this function set and change the
// frame for the plot. This way the colorbar is not part of
// the "associated" plot and so is not modified by a zoom or
// a rotation of the plot.
//
//
// EXAMPLES
// see the help page
// Check number of input argument
[lhs, rhs] = argn();
if rhs < 2 then
error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"), "colorbar", 2, 4));
end
nb_grad = 5
if ~exists("fmt","local") then
fmt="%-5.2g";
else
if type(fmt)<>10|size(fmt,"*")<>1 then
error(msprintf(gettext("%s: Wrong type for input argument #%d: %s data structure expected.\n"), "colorbar", 4, "string (containing a C format)"));
end
end
f=gcf();
if ~exists("colminmax","local") then
nb_colors = size(f.color_map,1)
colminmax = [1 nb_colors]
else
nb_colors = colminmax(2) - colminmax(1) + 1
end
//defer the drawing to avoid binking
id=f.immediate_drawing=="on";
if id then f.immediate_drawing=="off",end
// get current axes and properties
a=gca();
fg_color=a.foreground
wr=a.axes_bounds; //get the rectangle of the current axes
// modify the orginal axes to let space for the colorbar
a_pl=a;
a_pl.axes_bounds=[wr(1) , wr(2) , 0.85*wr(3) , wr(4)]
// create a new axes for the colorbar et set its properties
a_cb = newaxes(a.parent);
a_cb.axes_bounds=[wr(1)+0.83*wr(3) , wr(2)+wr(4)*0.2 , 0.2*wr(3) , wr(4)*0.6];
a_cb.data_bounds=[0 umin;1 umax];
a_cb.foreground=a.foreground;
a_cb.background=f.background;
a_cb.axes_visible="on";
a_cb.y_location = "right";
a_cb.tight_limits ="on";
//It is not possible to set no ticks for x (should be fixed)
a_cb.x_ticks=tlist(["ticks","locations","labels"],-1,"");
ytics = linspace(umin, umax, nb_grad);
a_cb.y_ticks=tlist(["ticks","locations","labels"],ytics', " "+msprintf(fmt+"\n",ytics'));
a_cb.auto_ticks = ["off","off","on"];
a_cb.box = "on";
a_cb.margins=[0 0.75 0 0];
//draw the colorbar
y = linspace(umin,umax,nb_colors)
col=[colminmax(1):colminmax(2)]
Sgrayplot([0 1],y,[col;col],colminmax=colminmax)
//reset the initial values
sca(a_pl) //current axes
if id then f.immediate_drawing="on",end //drawing mode
endfunction
trunk/plotlib/macros/scilab_plot.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2004-2006 - INRIA - Fabrice Leray
// Copyright (C) 2008 - INRIA - Jean-Baptiste Silvy
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function scilab_plot(varargin)
// Try to build a new better parser that could manage things like:
// plot(x,y,'X',1:10); // where X stands for Xdata (Matlab recognizes
//it and treats it well...)
[lhs,rhs]=argn(0);
if ~rhs
//LineSpec and PropertySpec examples:
t = 0:%pi/20:2*%pi;
tt = t';
clf('reset');
drawlater();
subplot(211);
scilab_plot(tt, sin(tt), "ro-.", tt, cos(tt), "cya+", tt, abs(sin(tt)), "--mo");
subplot(212);
scilab_plot([t ;t],[sin(t); cos(t)],"xdat",[1:2]);
drawnow();
return;
end
CurColor = 0; // current color used if no color specified via LineSpec
// nor PropertyName
ListArg = varargin;
//detect and set the current axes now:
if type(ListArg(1)) == 9
hdle = ListArg(1);
if (hdle.type == "Axes")
sca(ListArg(1));
ListArg(1) = null(); // remove this parameter from the list
else
warning("Handle should be an Axes handle")
return;
end
end
nv = size(ListArg)
argTypes=[];
couple=[];
typeOfPlot = "plot";
provided_data = 2;
for curArgIndex=1:nv
argTypes(curArgIndex,1) = type(ListArg(curArgIndex))
end
Ttmp=argTypes;
for i=1:nv-1
acceptedTypes=[];
acceptedTypes=find(Ttmp(i,1)==1 & or(Ttmp(i+1,1)==[1,13,130])) // to accept double, macro function or primitive as second argument
if (acceptedTypes<>[]) then
couple=[couple i];
Ttmp(i,1) = 99; // Replace a known type by 99 (no meaning) to count it once only!
Ttmp(i+1,1)= 99; // to avoid having (x1,y1,x2,y2) ->couple=[1,2,3]
// With this trick, couple=[1,3];
end
end
if (couple==[]) // No data couple found
// Search for at least a single data , i.e.: plot(y)
if ((argTypes(1,1)==1 | argTypes(1,1)==8) & ListArg(1)<>[]) then // case plot(SINGLE y,...)
couple = 1;
provided_data = 1;
if (modulo(nv-couple,2)<>0) then
P1 = couple+2 // Position of the first PropertyName field
else
P1 = couple+1
end
else
warning("Error inside input argument : no data");
return;
end
else
// Some test to check wrong inputs
//
// 1. Test if 2 data couples (first : type==1, second : type=[1,13,130])
// are at least separated by 2 indices
if (size(couple, "*") > 1 && couple(2:$)-couple(1:$-1)<2)
warning("Error inside input argument !");
return;
end
// 2. Test if no string couples happen before P1 (see below for P1 definition)
for index=1:couple($)
acceptedTypes=[];
acceptedTypes=find(Ttmp(index,1)==10 & Ttmp(index+1,1)==10)
if (acceptedTypes<>[]) then
warning("Error inside input argument : String argument is an unknown option.");
return;
end
end
if (modulo(nv-(couple($)+1),2)<>0) then
P1 = couple($)+3 // Position of the first PropertyName field
else
P1 = couple($)+2
end
end
numplot = size(couple,"*");
xyIndexLineSpec = zeros(numplot,3);
// xyIndexLineSpec is a matrix storing the index of x, y and linespec
// if one of these indices is 0 => it does not exist
// (which is possible for x and linepsec, not for y)
if (provided_data == 2) then
for curCouple=1:size(couple,"*")
xyIndexLineSpec(curCouple,1:2) = couple(curCouple) +[0,1] // x,y index storage
if (couple(curCouple)+2 < P1)
if (argTypes(couple(curCouple)+2,1)==10) then // LineSpec treatment
xyIndexLineSpec(curCouple,3) = couple(curCouple)+2;
end
end
end
else
// we are in the case where: plot(SINGLE y,... x not specified
// or plot(handle,SINGLE y,...
xyIndexLineSpec(1,1) = 0; // no x specified
xyIndexLineSpec(1,2) = couple;
//pause;
if (couple+1 < P1)
if (argTypes(couple+1,1)==10) then // LineSpec treatment
xyIndexLineSpec(1,3) = couple+1;
end
end
end
// delay the drawing commands
// smart drawlater
current_figure=gcf();
cur_draw_mode = current_figure.immediate_drawing;
current_figure.immediate_drawing = "off";
// check whether this is the first plot for the axes in which we will draw
curAxes = gca();
// save auto_clear state.
OldAutoClear = curAxes.auto_clear;
isFirstPlot = (curAxes.children == [])
//Now, we plot the decomposed plots one by one with their own linespec
// provided_data = 2 : x and y are provided
FinalAgreg=[]; // Final Compound containing all the new created plots.
//for i=numplot:-1:1
for i=1:numplot
// Set off auto_clear for allowing multiple graphics entity
// will be restored behond
if i>1 then
curAxes.auto_clear="off";
end
//default values
Marker=[];
MarkerSize=1;
Color=[];
LineStyle=1;
Line = %F;
Marker = %F;
if (provided_data == 2) then
if (type(ListArg(xyIndexLineSpec(i,2))) == 13 | type(ListArg(xyIndexLineSpec(i,2))) == 130)
// A function (macro or primitive) is given. We need to build the vector or matrix.
sizefirstarg = size(ListArg(xyIndexLineSpec(i,1)));
buildFunc = ListArg(xyIndexLineSpec(i,2));
firstarg = ListArg(xyIndexLineSpec(i,1));
tmp = [];
for ii=1:sizefirstarg(1,2)
for jj=1:sizefirstarg(1,1)
// function evaluation may fail
// try/cacth is buggy for now
// so use execstr until the bug is fixed
err = execstr("tmp(jj,ii) = buildFunc(firstarg(jj,ii))","errcatch","n");
if (err <> 0) then
// reset data
ResetFigureDDM(current_figure, cur_draw_mode);
// get error
[err_message, err_number, err_line, err_func] = lasterror(%t);
clear buildFunc;
// print it
if (err_func <> "") then
// ascii(10) = \n
error(msprintf(gettext("%s: Error : unable to evaluate input function ''%s''.") + ascii(10) + gettext("Error %d at line %d of the function: ''%s''"), "plot", err_func,err_number, err_line, err_message));
else
error(msprintf(gettext("%s: Error : unable to evaluate input function.") + ascii(10) + gettext("Error %d at line %d of the function: ''%s''"), "plot", err_number, err_line, err_message));
end
// exit function
return;
end
end
end
ListArg(xyIndexLineSpec(i,2)) = tmp;
// if there is an other iteration, we will have error message redefining function.
// we need to clear here and not before, because user must see the warning if needed.
clear buildFunc;
end
[X,Y] = checkXYPair(typeOfPlot,ListArg(xyIndexLineSpec(i,1)),ListArg(xyIndexLineSpec(i,2)),current_figure,cur_draw_mode)
else
if or(size(ListArg(xyIndexLineSpec(1,2)))==1) // If this is a vector
if size(ListArg(xyIndexLineSpec(1,2)), "r") == 1 then
X=1:length(ListArg(xyIndexLineSpec(1,2))); // insert a column abcsissa vector of same length,
else
X=(1:length(ListArg(xyIndexLineSpec(1,2))))'; // insert a row abcsissa vector of same length,
end
else // if this is a matrix,
X=(1:size(ListArg(xyIndexLineSpec(1,2)),1))'; // insert a row abcsissa vector with same size
end
// In both cases (matrix/vector), transpose it now so no warning is issued in checkXYPair().
[X,Y] = checkXYPair(typeOfPlot,X,ListArg(xyIndexLineSpec(1,2)),current_figure,cur_draw_mode)
end
// Case if 'Xdata', 'Ydata' or 'Zdata' have been set in (PropertyName,Propertyvalue) couples
// must be taken into account now
// P1 is the position of the first PropertyName field.
Property = P1;
while (Property <= nv-1)
PropertyName = ListArg(Property);
PropertyValue = ListArg(Property+1);
// Xdata can ONLY be a vector (cf. Matlab help)
PName = getPlotPropertyName(PropertyName,current_figure,cur_draw_mode);
if (PName == "xdata")
if (type(PropertyValue)<>1 | and(size(PropertyValue)<>1))
warning("Xdata value must be a column or row vector.");
ResetFigureDDM(current_figure, cur_draw_mode);
return;
else
PropertyValue = PropertyValue(:); // force
if or(size(X))==1 // If X is a vector (inevitably a column vector because checkXYPair always returns a column vector)
X = PropertyValue; // X is replaced by PropertyValue
[X,Y] = checkXYPair(typeOfPlot,X,Y,current_figure,cur_draw_mode)
else // X is a matrix
if size(PropertyValue,"*") == size(X,1)
for j=1:size(PropertyValue,"*")
X(j,:) = PropertyValue(j,1);
end
else
str="plot : incompatible dimensions in input arguments";
warning(str);
ResetFigureDDM(current_figure, cur_draw_mode);
end
end
end
// Ydata ONLY be a vector (contrary to what is said by the Matlab help)
elseif (PName == "ydata")
if (type(PropertyValue)<>1 | and(size(PropertyValue)<>1))
warning("Ydata value must be a column or row vector.");
ResetFigureDDM(current_figure, cur_draw_mode);
return;
else
PropertyValue = PropertyValue(:); // force
if or(size(Y))==1 // If Y is a vector (inevitably a column vector because checkXYPair always returns a column vector)
Y = PropertyValue; // Y is replaced by PropertyValue
[X,Y] = checkXYPair(typeOfPlot,X,Y,current_figure,cur_draw_mode)
else // Y is a matrix
if size(PropertyValue,"*") == size(Y,1)
for j=1:size(PropertyValue,"*")
Y(j,:) = PropertyValue(j);
end
else
str="plot : incompatible dimensions in input arguments";
warning(str);
ResetFigureDDM(current_figure, cur_draw_mode);
end
end
end
// Zdata will be treated after plot building
end
Property = Property+2;
end
//Now we have an array xyIndexLineSpec [numplot x 3] containing indices pointing on T for :
// - x (<>0 if existing)
// - y
// - linespec (<>0 if existing)
// for each plot passed in argument
// x | y | linespec
// ----------------
//plot1 0|i1 |0 <=> plot(y)
//plot2 i2|i3 |0 <=> plot(x,y)
//plot3 i4|i5 |i6 <=> plot(x,y,LINESPEC)
//...
if (xyIndexLineSpec(i,3)<>0) then // if we have a line spec <=> index <> 0
[Color,Line,LineStyle,Marker,MarkerStyle,MarkerSize,fail] = getLineSpec(ListArg(xyIndexLineSpec(i,3)),current_figure,cur_draw_mode);
end
// The plot is made now :
err = execstr("plot2d(X,Y)","errcatch","m");
if err <> 0
mprintf("Error %d : in plot2d called by plot",err);
ResetFigureDDM(current_figure, cur_draw_mode);
return;
end
agreg=gce(); // when using plot2d, we always have an Compound as the current entity
FinalAgreg = [agreg FinalAgreg];
if Color==[]
DefaultColor = %T;
else
DefaultColor = %F;
end
for ii=size(agreg.children,"*"):-1:1
curPolyline=agreg.children(ii); // we apply linespec to the lines
// Color treatment : if no color specified by LineSpec nor PropertyName
// Set the default color to the curve
if DefaultColor == %T
[Color,CurColor] = setDefaultColor(CurColor);
end
if (Marker == %T)
curPolyline.mark_style=MarkerStyle;
curPolyline.mark_mode ="on";
curPolyline.mark_foreground = Color;
curPolyline.mark_style=MarkerStyle;
curPolyline.mark_size=MarkerSize;
else
curPolyline.mark_mode ="off"
end
if (Line == %T)
curPolyline.line_mode="on";
curPolyline.foreground = Color;
curPolyline.line_style = LineStyle;
else
curPolyline.line_mode="off"
end
if (Line == %F & Marker ==%F) // no linespec nor PropertyName set
curPolyline.line_mode="on";
curPolyline.foreground = Color;
curPolyline.line_style = LineStyle;
end
end
end
//Reset auto_clear Property
curAxes.auto_clear = OldAutoClear;
///////////////////////////////////
//Global Property treatment //
//PropertyName and PropertyValue //
///////////////////////////////////
// Those properties will be applied to Agreg children
Agreg = glue(FinalAgreg(1:$))
nbCompound = find(Agreg.children.type=="Compound")
while (nbCompound<>[])
nbCompound=nbCompound(1);
unglue(Agreg.children(nbCompound));
nbCompound=find(Agreg.children.type=="Compound")
end
// P1 is the position of the first PropertyName field.
Property = P1;
Curves = Agreg.children
//Curves(:,1) = Curves(:,$:-1:1);
// set mark_size_unit to 'point' for all the curves
Curves.mark_size_unit="point";
while (Property <= nv-1)
setPlotProperty(ListArg(Property),ListArg(Property+1),Curves,current_figure,cur_draw_mode)
Property = Property+2;
end
// force drawing of box like in matlab
// for a first plot
// unless we are using centered axes
// to keep compatibility with Scilab 4
if isFirstPlot & curAxes.x_location <> "origin" & curAxes.y_location <> "origin" then
curAxes.box = "on";
end
//postponed drawings are done now !
// smart drawnow
ResetFigureDDM(current_figure, cur_draw_mode)
endfunction
trunk/plotlib/macros/scilab_subplot.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function scilab_subplot(m,n,p)
[lhs,rhs]=argn(0)
if rhs<>3 & rhs<>1 then
error(msprintf(gettext("%s: Wrong number of input argument(s): %d or %d expected."), "subplot", 1, 3));
return
end
if rhs==1 then
p=modulo(m,10)
n=modulo((m-p)/10,10)
m=(m-p-10*n)/100
end
if m*n*p==0 then
error(msprintf(gettext("%s: Wrong value for input argument #%d: A %d digits integer with digits greater than %d expected.\n"),"subplot",1,3,0));
return
end
j=int((p-1)/n)
i=p-1-n*j
axes_bounds=[i/n,j/m,1/n,1/m];
a = gca();
f = a.parent;
na=size(f.children,"*")
if na==1 then
// an axes is automatically created when a figure is created
// do not create a new axes if we have just this one
a=f.children;da=gda()
if a.children==[]& and(a.axes_bounds==da.axes_bounds) then
//a single axes with no children, just resize it
a.axes_bounds=axes_bounds;
return
end
end
// look for an axes with the same axes_bounds
for k=1:na
child = f.children(k);
if child.type == "Axes" & and(child.axes_bounds == axes_bounds) then
//make it current
sca(child);
return;
end
end
//create a new axes
a=newaxes(f);
a.axes_bounds=axes_bounds;
sca(a);
endfunction
trunk/plotlib/macros/scilab_gcf.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function [f]=scilab_gcf()
f=get("current_figure");
endfunction
trunk/plotlib/macros/scilab_surf.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2004-2006 - INRIA - Fabrice Leray
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function surf(varargin)
[lhs,rhs]=argn(0);
if ~rhs
Z= [ 0.0001 0.0013 0.0053 -0.0299 -0.1809 -0.2465 -0.1100 -0.0168 -0.0008 -0.0000; ..
0.0005 0.0089 0.0259 -0.3673 -1.8670 -2.4736 -1.0866 -0.1602 -0.0067 0.0000; ..
0.0004 0.0214 0.1739 -0.3147 -4.0919 -6.4101 -2.7589 -0.2779 0.0131 0.0020; ..
-0.0088 -0.0871 0.0364 1.8559 1.4995 -2.2171 -0.2729 0.8368 0.2016 0.0130; ..
-0.0308 -0.4313 -1.7334 -0.1148 3.0731 0.4444 2.6145 2.4410 0.4877 0.0301; ..
-0.0336 -0.4990 -2.3552 -2.1722 0.8856 -0.0531 2.6416 2.4064 0.4771 0.0294; ..
-0.0137 -0.1967 -0.8083 0.2289 3.3983 3.1955 2.4338 1.2129 0.2108 0.0125; ..
-0.0014 -0.0017 0.3189 2.7414 7.1622 7.1361 3.1242 0.6633 0.0674 0.0030; ..
0.0002 0.0104 0.1733 1.0852 2.6741 2.6725 1.1119 0.1973 0.0152 0.0005; ..
0.0000 0.0012 0.0183 0.1099 0.2684 0.2683 0.1107 0.0190 0.0014 0.0000];
f=gcf();
f.color_map = jetcolormap(64);
surf(Z,"edgeco","b","marker","d","markersiz",9,"markeredg","red","markerfac","k");
return;
end
X=[];
Y=[];
Z=[];
C=[];
CurColor = 0; // current color used if no color specified via LineSpec
// nor PropertyName
ListArg = varargin;
//detect and set the current axes now:
if type(ListArg(1)) == 9
hdle = ListArg(1);
if (hdle.type == "Axes")
sca(ListArg(1));
ListArg(1) = null(); // remove this parameter from the list
else
error(msprintf(gettext("%s: Wrong type for input argument #%d: An ''Axes'' handle expected.\n"), "surf", 1));
return;
end
end
nv = size(ListArg)
T=[];
d=[];
typeOfPlot = "surf";
//given_data = 2;
for k=1:nv
T(k,1) = type(ListArg(k))
end
given_data = 0;
P1 = 0;
for i=1:nv
if T(i) == 1
given_data = given_data +1;
else
P1 = i; // Position of the first PropertyName field
break;
end
end
// delay the drawing commands
// smart drawlater
current_figure=gcf();
cur_draw_mode = current_figure.immediate_drawing;
current_figure.immediate_drawing = "off";
colormap_size = size(current_figure.color_map,1);
if given_data == 1 //surf(Z) with Z giving us data + color info.
// ---------------------------------------------------------- //
if or(size(ListArg(1))==1)
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input argument #%d: A matrix of size greater than %d-by-%d expected.\n"), "surf", 1, 2, 2));
return;
end
X = 1:size(ListArg(1),2);
Y = 1:size(ListArg(1),1);
Z = ListArg(1)'; // here a transposition is needed
C = Z;
[XX,YY,ZZ] = genfac3d(X,Y,Z);
CC = ZZ; // Add a color matrix based on Z values
elseif given_data == 2 //surf(Z,COLOR)
// ---------------------------------------------------------- //
if or(size(ListArg(1))==1)
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input argument #%d: A matrix of size greater than %d-by-%d expected.\n"), "surf", 1, 2, 2));
return;
end
if ((size(ListArg(1)) <> size(ListArg(2))) & (size(ListArg(1))-1 <> size(ListArg(2))))
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input argument #%d: A %d-by-%d or %d-by-%d matrix expected.\n"),..
"surf", 2, size(ListArg(1),1), size(ListArg(1),2), size(ListArg(1),1) - 1, size(ListArg(1),2) -1 ));
return;
end
X = 1:size(ListArg(1),2);
Y = 1:size(ListArg(1),1);
Z = ListArg(1)'; // here a transposition is needed
C = ListArg(2)';
[XX,YY,ZZ] = genfac3d(X,Y,Z);
if (size(ListArg(2)) == size(ListArg(1))) // color number == zdata number
[XX,YY,CC] = genfac3d(X,Y,C); // CC must be a color matrix of size nf x n
elseif ((size(ListArg(2))) == size(ListArg(1))-1) // color number -1 == zdata number => ONLY flat mode can be enabled
Ctmp=[];
Ctmp = [C [C(:,$)]] ;
Ctmp = [Ctmp; Ctmp($,:)];
[XX,YY,CC] = genfac3d(X,Y,Ctmp); // CC must be a color matrix of size nf x n
end
elseif given_data == 3 //surf(X,Y,Z) with Z giving us data + color info.
// ---------------------------------------------------------- //
X = ListArg(1)
Y = ListArg(2);
Z = ListArg(3);
// check if the call is OK
err = execstr("[XX,YY,ZZ,CC] = CreateFacetsFromXYZ(X,Y,Z,current_figure, cur_draw_mode)","errcatch","n");
if (err <> 0) then
// reset data
processSurfError(current_figure, cur_draw_mode);
end
elseif given_data == 4 //surf(X,Y,Z,COLOR)
// ---------------------------------------------------------- //
if ((size(ListArg(3)) <> size(ListArg(4))) & (size(ListArg(3))-1 <> size(ListArg(4))))
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input argument #%d: A %d-by-%d or %d-by-%d matrix expected.\n"),..
"surf", 4, size(ListArg(3),1), size(ListArg(3),2), size(ListArg(3),1) - 1, size(ListArg(3),2) -1 ));
return;
end
X = ListArg(1)
Y = ListArg(2);
Z = ListArg(3);
C = ListArg(4);
// check if the call is OK
err = execstr("[XX,YY,ZZ,CC] = CreateFacetsFromXYZColor(X,Y,Z,C,current_figure, cur_draw_mode)","errcatch","n");
if (err <> 0) then
// reset data
processSurfError(current_figure, cur_draw_mode);
end
end
// P1 is the position of the first PropertyName field.
Property = P1;
while ((Property <> 0) & (Property <= nv-1))
PropertyName = ListArg(Property);
PropertyValue = ListArg(Property+1);
// Xdata
PName = getSurfPropertyName(PropertyName);
if (PName == "xdata")
if (type(PropertyValue)<>1)
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong type for input argument ''%s'': A Real matrix expected.\n"), "surf", "xdata"));
return;
end
X = PropertyValue;
[XX,tmp2,tmp3] = CreateFacetsFromXYZ(PropertyValue,Y,Z,current_figure, cur_draw_mode);
// Ydata
elseif (PName == "ydata")
if (type(PropertyValue)<>1)
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong type for input argument ''%s'': A Real matrix expected.\n"), "surf", "ydata"));
return;
end
Y = PropertyValue;
[tmp1,YY,tmp3] = CreateFacetsFromXYZ(X,PropertyValue,Z,current_figure, cur_draw_mode);
// Zdata
elseif (PName == "zdata")
if (type(PropertyValue)<>1) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong type for input argument ''%s'': A Real matrix expected.\n"), "surf", "zdata"));
return;
end
if (or(size(PropertyValue)==1)) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input argument ''%s'': A matrix of size greater than %d-by-%d expected.\n"), "surf", "zdata", 2, 2));
return;
end
Z = PropertyValue;
[tmp1,tmp2,ZZ] = CreateFacetsFromXYZ(X,Y,PropertyValue,current_figure, cur_draw_mode);
end
Property = Property+2;
end
if isempty(XX) | isempty(YY) | isempty(ZZ) then
// Nothing will be drawn so return (see http://bugzilla.scilab.org/13180 )
return
end
// surf is made now !
// with default option to simulate the Matlab mode
err = execstr("plot3d(XX,YY,list(ZZ,CC))","errcatch","n");
if err <> 0
processSurfError(current_figure, cur_draw_mode);
end
a=gca();
a.cube_scaling = "on";
a.rotation_angles = [51 -125];
e=gce();
e.hiddencolor=0; // to avoid painting the hidden facets
e.color_flag=4; // Matlab special flat mode by default (different from mode 2)
e.cdata_mapping = "scaled"
// F.Leray
// Today: 17.03.05
// XYZ-DataMode under Matlab seems really bugged (see following samples and read Matlab doc.):
//
// surf(X,Y,Z,'XDataMode','auto')
// surf(X,Y,Z,'XDataMode','auto')
// surf(X+20,Y,Z,'XDataMode','auto')
// surf(X+20,Y,Z,'XDataMode','man')
// surf(X+20,Y,Z,'XDataMode','auto')
// surf(X+20,Y,Z,'Xdata',X-100,'XDataMode','auto')
// surf(X+20,Y,Z,'Xdata',X-100,'XDataMode','man')
// surf(X+20,Y,Z,'XData',X-100,'XDataMode','auto')
// surf(X+20,Y,Z,'XData',X-100,'XDataMode','man')
// surf(Z,'XData',X-100,'XDataMode','man')
// surf(Z,'XData',X-100,'XDataMode','auto')
// surf(X+20,Y,Z,'XDataMode','man')
// surf(X+20,Y,Z,'XDataMode','auto')
//
// That is why I do not support those properties.
// Below and in comment is the code we could add to treat those properties.
// by giving XYZ-DataModeVal to setSurfProperty (to better treat XYZ-Data input).
//
//
//XdataModeVal=1;
//YdataModeVal=1;
//ZdataModeVal=1;
//
//if Property <> 0
// XdataMode = getIndexInStringTable('xdatam',ListArg([Property nv]))
// if XdataMode <> []
// XdataModeVal = getIndexInStringTable(ListArg(XdataMode+1),['auto','manual'])
// if size(XdataModeVal,'*') <> 1
// disp("Error: Bad XdataMode selected");
// return;
// end
// end
//
// YdataMode = getIndexInStringTable('ydatam',ListArg([Property nv]))
// if YdataMode <> []
// YdataModeVal = getIndexInStringTable(ListArg(YdataMode+1),['auto','manual'])
// if size(YdataModeVal,'*') <> 1
// disp("Error: Bad YdataMode selected");
// return;
// end
// end
//
// ZdataMode = getIndexInStringTable('zdatam',ListArg([Property nv]))
// if ZdataMode <> []
// ZdataModeVal = getIndexInStringTable(ListArg(ZdataMode+1),['auto','manual'])
// if size(ZdataModeVal,'*') <> 1
// disp("Error: Bad ZdataMode selected");
// return;
// end
// end
//end
//
///////////////////////////////////
//Global Property treatment //
//PropertyName and PropertyValue //
///////////////////////////////////
// P1 is the position of the first PropertyName field.
Property = P1;
current_surface = gce(); // get the newly created fac3d
current_surface.mark_size_unit="point";
while ((Property <> 0) & (Property <= nv-1))
setSurfProperty(ListArg(Property),ListArg(Property+1),current_surface,X,Y,Z,C,current_figure,cur_draw_mode)
Property = Property+2;
end
//postponed drawings are done now !
// smart drawnow
ResetFigureDDM(current_figure, cur_draw_mode);
endfunction
//
//function [C] = build_interp_color(C,colormap_size)
//// C is considered as a data value in Matlab
//MIN = min(C);
//MAX = max(C);
//NCOLMIN = 1;
//NCOLMAX = colormap_size;
//
//if MIN <> MAX
// C = (NCOLMIN-NCOLMAX)/(MIN-MAX) * C + (MIN*NCOLMAX - NCOLMIN*MAX)/(MIN-MAX);
// C = round(C);
//else
// C = ones(C) * (NCOLMIN+NCOLMAX)/2;
//end
//endfunction
//
//
function k=getIndexInStringTable(pattern,table)
str = convstr(pattern);
k=find(part(table,1:length(str))==str);
endfunction
function [XX,YY,ZZ,CC] = CreateFacetsFromXYZ(X,Y,Z,current_figure, cur_draw_mode)
if or(size(X)==1) & or(size(Y)==1) // X and Y are vector
tmp = X;
X = Y;
Y = tmp;
if size(X,"*") ~= size(Z,1) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input argument ''%s'': A vector of size %d expected.\n"), "surf", "Y", size(Z,1)));
return;
end
if size(Y,"*") ~= size(Z,2) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input argument ''%s'': A vector of size %d expected.\n"), "surf", "X", size(Z,2)));
return;
end
[XX,YY,ZZ] = genfac3d(Y,X,Z');
// COLOR treatment
CC = ZZ;
elseif and(size(X)>1) & and(size(Y)>1) // X and Y are matrix
if or(size(X) ~= size(Y)) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input arguments ''%s'' and ''%s'': Matrices of same size expected.\n"), "surf", "X", "Y"));
return;
end
if or(size(X) ~= size(Z)) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input arguments ''%s'' and ''%s'': Matrices of same size expected.\n"), "surf", "X", "Z"));
return;
end
[XX,YY,ZZ] = nf3d(X,Y,Z);
// COLOR treatment
CC = ZZ;
elseif or(size(X)==1) & and(size(Y)>1) // X is a vector and Y is a matrix
if size(X,"*") ~= size(Z,2) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input argument ''%s'': A vector of size %d expected.\n"), "surf", "X", size(Z,2)));
return;
end
if or(size(Y) ~= size(Z)) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input arguments ''%s'' and ''%s'': Matrices of same size expected.\n"), "surf", "Y", "Z"));
return;
end
// X vector
// Y matrix
// Z matrix
X=X(:)'; // X is forced to be a row vector
XMAT=[];
for i=1:size(Z,2)
XMAT=[XMAT;X];
end
[XX,YY,ZZ] = nf3d(XMAT,Y,Z);
// COLOR treatment
CC = ZZ;
elseif or(size(Y)==1) & and(size(X)>1) // Y is a vector and X is a matrix
if or(size(X) ~= size(Z)) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input arguments ''%s'' and ''%s'': Matrices of same size expected.\n"), "surf", "X", "Z"));
return;
end
if size(Y,"*") ~= size(Z,2) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input argument ''%s'': A vector of size %d expected.\n"), "surf", "Y", size(Z,2)));
return;
end
// Y vector
// X matrix
// Z matrix
Y=Y(:); // Y is forced to be a column vector
YMAT=[];
for i=1:size(Z,1)
YMAT=[YMAT,Y];
end
[XX,YY,ZZ] = nf3d(X,YMAT,Z);
// COLOR treatment
CC = ZZ;
else
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input arguments ''%s'' and ''%s'': Same size expected.\n"), "surf", "X", "Y"));
return;
end
endfunction
function [XX,YY,ZZ,CC] = CreateFacetsFromXYZColor(X,Y,Z,C,current_figure, cur_draw_mode)
if or(size(X)==1) & or(size(Y)==1) // X and Y are vector
Z = Z'; // here a transposition is needed
C = C'; // here a transposition is needed
if size(X,"*") ~= size(Z,1) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input argument ''%s'': A vector of size %d expected.\n"), "surf", "X", size(Z,1)));
return;
end
if size(Y,"*") ~= size(Z,2) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input argument ''%s'': A vector of size %d expected.\n"), "surf", "Y", size(Z,2)));
return;
end
[XX,YY,ZZ] = genfac3d(X,Y,Z);
// COLOR treatment
if (size(C) == size(Z)) // color number == zdata number
[XX,YY,CC] = genfac3d(X,Y,C); // CC must be a color matrix of size nf x n
elseif (size(C) == size(Z)-1) // color number -1 == zdata number => ONLY flat mode can be enabled
Ctmp=[];
Ctmp = [C [C(:,$)]] ;
Ctmp = [Ctmp; Ctmp($,:)];
[XX,YY,CC] = genfac3d(X,Y,Ctmp); // CC must be a color matrix of size nf x n
end
elseif and(size(X)>1) & and(size(Y)>1) // X and Y are matrices
if or(size(X) ~= size(Y)) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input arguments ''%s'' and ''%s'': Matrices of same size expected.\n"), "surf", "X", "Y"));
return;
end
if or(size(X) ~= size(Z)) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input arguments ''%s'' and ''%s'': Matrices of same size expected.\n"), "surf", "X", "Z"));
return;
end
[XX,YY,ZZ] = nf3d(X,Y,Z);
// COLOR treatment
if (size(C) == size(Z)) // color number == zdata number
[XX,YY,CC] = nf3d(X,Y,C); // CC must be a color matrix of size nf x n
elseif (size(C) == size(Z)-1) // color number -1 == zdata number => ONLY flat mode can be enabled
Ctmp=[];
Ctmp = [C [C(:,$)]] ;
Ctmp = [Ctmp; Ctmp($,:)];
[XX,YY,CC] = nf3d(X,Y,Ctmp); // CC must be a color matrix of size nf x n
end
elseif or(size(X)==1) & and(size(Y)>1) // X is a vector and Y is a matrix
if size(X,"*") ~= size(Z,2) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input argument ''%s'': A vector of size %d expected.\n"), "surf", "X", size(Z,2)));
return;
end
if or(size(Y) ~= size(Z)) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input arguments ''%s'' and ''%s'': Matrices of same size expected.\n"), "surf", "Y", "Z"));
return;
end
// X vector
// Y matrix
// Z matrix
X=X(:)'; // X is forced to be a row vector
XMAT=[];
for i=1:size(Z,2)
XMAT=[XMAT;X];
end
[XX,YY,ZZ] = nf3d(XMAT,Y,Z);
// COLOR treatment
if (size(C) == size(Z)) // color number == zdata number
[XX,YY,CC] = nf3d(XMAT,Y,C); // CC must be a color matrix of size nf x n
elseif (size(C) == size(Z)-1) // color number -1 == zdata number => ONLY flat mode can be enabled
Ctmp=[];
Ctmp = [C [C(:,$)]] ;
Ctmp = [Ctmp; Ctmp($,:)];
[XX,YY,CC] = nf3d(XMAT,Y,Ctmp); // CC must be a color matrix of size nf x n
end
elseif or(size(Y)==1) & and(size(X)>1) // Y is a vector and X is a matrix
if or(size(X) ~= size(Z)) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input arguments ''%s'' and ''%s'': Matrices of same size expected.\n"), "surf", "X", "Z"));
return;
end
if size(Y,"*") ~= size(Z,2) then
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input argument ''%s'': A vector of size %d expected.\n"), "surf", "Y", size(Z,2)));
return;
end
// Y vector
// X matrix
// Z matrix
Y=Y(:); // Y is forced to be a column vector
YMAT=[];
for i=1:size(Z,1)
YMAT=[YMAT,Y];
end
[XX,YY,ZZ] = nf3d(X,YMAT,Z);
// COLOR treatment
if (size(C) == size(Z)) // color number == zdata number
[XX,YY,CC] = nf3d(X,YMAT,C); // CC must be a color matrix of size nf x n
elseif (size(C) == size(Z)-1) // color number -1 == zdata number => ONLY flat mode can be enabled
Ctmp=[];
Ctmp = [C [C(:,$)]] ;
Ctmp = [Ctmp; Ctmp($,:)];
[XX,YY,CC] = nf3d(X,YMAT,Ctmp); // CC must be a color matrix of size nf x n
end
else
ResetFigureDDM(current_figure, cur_draw_mode);
error(msprintf(gettext("%s: Wrong size for input arguments ''%s'' and ''%s'': Matrices of same size expected.\n"), "surf", "X", "Y"));
return;
end
endfunction
// If an error occurs in the surf code, we need to catch it
// order to reset some default values
function processSurfError(cur_figure, cur_draw_mode)
// reset data
ResetFigureDDM(current_figure, cur_draw_mode);
// get the error
[err_message, err_number, err_line, err_func] = lasterror(%t);
// rethrow it
// for now error can only have a single string as input.
// If there are several lines we need to concatane them.
err_message_nbLines = size(err_message, "*");
if (err_message_nbLines > 1) then
// put a \n betwee, each string
err_message(1) = strcat(err_message, "\n");
end
error(err_message(1), err_number);
endfunction
trunk/plotlib/macros/%axesData_i_h.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
//
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function h=%leafData_i_h(i,v,h)
hsave=h
// if v==[] then error('Field property cannot be []'),end
if type(i)==10 then set(h,i,v),return,end
if type(i)<>15 then error(msprintf(_("%s: Wrong type for input argument #%d.\n"),"generic_i_h",1)),end
if and(type(i($))<>[1 2 4 8 129 15]) then
i($+1)=:
end
n = size(i)
hdl=h;hind=[]
for k=1:size(i)// walk down in the handle tree
p=i(k)
lasthandle=hdl,
if type(p)==10 then
hdl=get(hdl,p),
elseif or(type(p)==[1 2 4 8 129]) then
hdl=hdl(p)
elseif type(p)==15 then
hdl=hdl(p(:))
else
error("Invalid path")
end
if type(hdl)<>9 then //a leaf found
property=hdl
hdl=lasthandle
hind=p
if (k+1)==size(i) then
index=i($)
else
index=list(i(k+1:$))
end
break
end
end
if hind<>[] then // a property found
if type(index)==15 & and(type(property)<>[15 16 17]) then
property(index(:))=v
else
if or(size(index)<>[-1 -1]) then
if (index(1)=="locations" | index(1)=="labels") & size(v,"*") ~= 1 & size(property(index),"*") ~= size(v,"*") then
error(msprintf(_("%s: Incompatible sizes for properties ''%s'' and ''%s'': Same sizes expected.\n"), "generic_i_h", string(i($-2))+".locations", string(i($-2))+".labels"));
end
property(index)=v
else
property=v
end
end
if size(hdl,"*")==1 then //a single handle
hdl(hind)=property
else //mutiple handle
np=size(hdl,"*")
for k=1:np
h=hdl(k);h(hind)=property
end
end
else
error(msprintf(_("%s: Wrong type for input argument #%d.\n"),"generic_i_h",1));
end
h = hsave
endfunction
trunk/plotlib/macros/scilab_gca.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function [a]=scilab_gca()
a=get("current_axes");
endfunction
trunk/plotlib/macros/scilab_mesh.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2004-2006 - INRIA - Farid Belahcene
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function scilab_mesh(varargin)
// Copyright INRIA
//
// Syntax:
// mesh(z)
// mesh(x,y,z)
// mesh(...,<GlobalProperty>)
// mesh(...,<color>,<GlobalProperty>)
// mesh(<axes_handle>,...)
//
// MESH function draws white surfaces, it's based on surf function with the properties e.color_mode = color('white') and e.color_flag = 0.
// Inputs
// x,y,z : matrices which define the grid
// Copy RHS arguments
ListArg = varargin;
drawlater();
scilab_surf(ListArg(:));
e = gce();
e.color_mode = color("white");
e.color_flag = 0;
drawnow();
endfunction

Archive Download the corresponding diff file

Revision: 77