File: chap5.tex

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (1073 lines) | stat: -rw-r--r-- 33,927 bytes parent folder | download
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
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
% Copyright INRIA

\chapter{Graphics}
This section introduces graphics in Scilab. 

\section{The Graphics Window}
It is possible to use several graphics windows {\tt ScilabGraphicx} x being
the number used for the management of the windows, but at any time only
one window is active. On the main Scilab window the button
 {\tt Graphic Window x} is used to manage the windows : x denotes the
number of the active window, and we can set (create), raise or delete 
the window numbered x : in particular we can directly create the 
graphics window numbered 10.
The execution of a plotting command automatically creates a window if 
necessary.

We will see later that Scilab uses a {\tt graphics environment}
defining some parameters of the plot, these parameters have default
values and can be changed by the user; every graphics window has its
specific context so the same plotting command van give different
results on different windows.

There are 4 buttons on the graphics window:
\begin{itemize}
	\item \verb+3D Rot.+: for applying a rotation with the mouse to a
3D plot. This button is inhibited for a 2D plot. For the help of
manipulations (rotation with specific angles ...) the rotation angles 
are given at the top of the window.
	\item \verb+2D Zoom+: zooming on a 2D plot. This command can be
recursively invoked. For a 3D plot this button is not inhibited but it
has no effect.
	\item \verb+UnZoom+: return to the initial plot (not to the plot
corresponding to the previous zoom in case of multiple zooms).

These 3 buttons affecting the plot in the window are not always in
use; we will see later that there are different choices for the 
underlying device and zoom and rotation need the record of the
plotting commands which is one of the possible choices (this is the
default).

	
	\item \verb+File+: this button opens different commands and menus.

The first one is simple : {\tt Clear} simply rubs out the window
(without affecting the graphics context of the window).

The command {\tt Print...} opens a selection panel for printing. 
The printers are defined in the main scilab script 
{\tt SCIDIR/bin/scilab} (obtained by ``make all'' from the origin 
file {\tt SCIDIR/bin/scilab.g}).

The {\tt Export} command opens a panel selection for getting a copy of the 
plot on a file with a specified format (Postscript, Postscript-Latex, Xfig).

The {\tt save} command directly saves the plot on a file with a
specified name. This file can be loaded later in Scilab for replotting.

The {\tt Close} is the same command than the previous {\tt Delete
Graphic Window} of the menu of the main window, but simply 
applied to its window (the graphic context is, of course deleted). 

\end{itemize}

 
\section{The Media}
There are different graphics devices in Scilab which can be used to send
graphics to windows or paper. The default for the output is 
\verb+ScilabGraphic0+ window .

\noindent The different drivers are:

%
\begin{itemize}
	\item \verb+X11+	: graphics driver for the X11 window system 
	\item \verb+Rec+	: an X Window driver (X11) which also
	records all the graphic commands. This is the default
	(required for the zoom and rotate).
	\item \verb+Wdp+	: an X11 driver without recorded
	graphics; the graphics are done on a pixmap and are send to
	the graphic window with the command  {\tt xset("wshow")}. The 
	pixmap is cleared with the command {\tt xset("wwpc")} or with the
	usual command {\tt xbasc()}
	\item \verb+Pos+	: graphics driver for Postscript printers 
	\item \verb+Fig+	: graphics driver for the Xfig system
\end{itemize}
%

In the 3 first cases the 'implicit' device is a graphics window
(existing or created by the plot). For the 2 last cases we will see
later how to affect a specific device to the plot : a file where the
plot will be recorded in the Postscript or Xfig format.

The basic Scilab graphics commands are :
%
\begin{itemize}
	\item \verb+driver+: selects a graphic driver

The next 3 commands are specific of the X-drivers :

	\item \verb+xclear+: clears one or more graphic windows; does
	not affect the graphics context of these windows.
	\item \verb+xbasc+: clears a graphic window and erase the
	recorded graphics; does not affect the graphics context of  
	the window.
	\item \verb+xpause+: a pause in milliseconds
	\item \verb+xselect+: raises the current graphic window
	(for X-drivers)
	\item \verb+xclick+: waits for a mouse click
	\item \verb+xbasr+: redraws the plot of a graphic window
	\item \verb+xdel+: deletes a graphic window (equivalent to the
	{\tt Close} button

The following commands are specific of the Postscript and Xfig 
drivers :
	
	\item \verb+xinit+: initializes a graphic device
	simply opens a graphics window for the X-drivers this command
	is necessary for Postscript and Xfig drivers.
	\item \verb+xend+: closes a graphic session (and the
	associated device).
\end{itemize}
%

In fact, the regular driver for a common use is {\tt Rec} and there
are special commands in order to avoid a change of driver; in many
cases, one can ignore the existence of drivers and use the
functions \verb+xbasimp+, \verb+xs2fig+ in order to send a graphic 
to a printer or in a file for the \verb+Xfig+ system. For example with
:

\begin{verbatim}
-->driver('Pos')
 
-->xinit('foo.ps')
 
-->plot(1:10)
 
-->xend()
 
-->driver('Rec')
 
-->plot(1:10)
 
-->xbasimp(0,'foo1.ps')

\end{verbatim}

\noindent we get two identical Postscript files : {\tt 'foo.ps'} and {\tt 'foo1.ps.0'}
(the appending 0 is the number of the active window where the plot has been 
done).

The default for plotting is the superposition; this means that between
2 different plots one of the 2 following command is needed :
{\tt xbasc(window-number)} which clears the window and erase the
recorded Scilab graphics command associated with the window 
\verb+window-number+ or {\tt xclear}) which simply clears the window.

If you enlarge a graphic window, the command \verb+xbasr(window-number)+
is executed by Scilab. This command clears the graphic window
\verb+window-number+ and replays the graphic commands associated with it. One 
can call this function manually, in order to verify the associated
recorded graphics commands. 

Any number of graphics windows can be created with buttons 
or with the commands \verb+xset+ or \verb+xselect+. The environment 
variable DISPLAY can be used to specify an X11 Display or one can use
the \verb+xinit+ function in order to open a graphic window on a
specific display. 

\section{Global Parameters of a Plot}
\subsubsection{Graphics Context}

Some parameters of the graphics are controlled by a graphic context 
( for example the line thickness) and others are controlled through
graphics arguments of a plotting command.
The graphics context has a default definition and can be change by the
command {\tt xset} : the command without argument i.e. {\tt xset()}
opens the {\tt Scilab Toggles Panel} and the user can changes the
parameters by simple mouse clickings. We give here different
parameters controlled by this command :
%
\begin{itemize}
	\item  {\tt xset}		: set graphic context values.

(i)-{\tt xset("font",fontid,fontsize)} 	: fix the current font and 
its current size.

(ii)-{\tt xset("mark",markid,marksize)}	: set the current mark 
and current mark size.

(iii)-{\tt xset("use color",flag)} 	: change to color or gray plot according to 
the values (1 or 0) of {\tt flag}.

(iv)-{\tt xset("colormap",cmap)} 	: set the colormap as a m x 3
matrix. m is the number of colors.  Color number i is given as a
3-uple cmap[i,1],cmap[i,2], cmap[i,3] corresponding respectively to Red,
Green and Blue intensity between 0 and 1. Calling again {\tt xset()} 
shows the colormap with the indices of the colors.

(v)-{\tt xset("window",window-number)}	: sets the current window to the window 
{\tt window-number} and creates the window if it doesn't exist.

(vi)-{\tt xset("wpos",x,y)}	: fixes the position of the upper left point of 
the graphic window.

Many other choices are done by {\tt xset} :
 
-use of a pixmap : the plot can be directly displayed on the screen or
executed on a pixmap and then expose by the command 
{\tt xset("wshow")}; this is the usual way for animation effect.

-logical function for drawing : this parameter can be changed for 
specific effects (superposition or adding or substracting of colors).
Looking at the successive plots of the following simple commands give
an example of 2 possible effects of this parameter :

\begin{verbatim}
xset('default');
plot3d();
plot3d();
xset('alufunction',7);
xset('window',0);
plot3d();
xset('default');
plot3d();
xset('alufunction',6);
xset('window',0);
plot3d();
\end{verbatim} 

We have seen that some choices exist for the fonts and this choice can
be extended by the command:
        \item  {\tt xlfont}	: to load a new family of fonts from
the XWindow Manager


There exists the function ``reciprocal'' to {\tt xset} :

	\item  {\tt xget}	: to get informations about the
	current graphic context.

All the values of the parameters fixed by {\tt xset} can be obtained by 
{\tt xget}. An example :

\begin{verbatim}

-->pos=xget("wpos")
 pos  =
 
!   105.    121. !

\end{verbatim}

{\tt pos} is the position of the upper left point of the graphic window.
\end{itemize}
%

\subsubsection{Some Manipulations}

Coordinates transforms:
\begin{itemize}
	\item \verb+isoview+	: isometric scale without window change 

allows an isometric scale in the window of previous plots without changing
the window size:

\begin{verbatim}

t=(0:0.1:2*%pi)';
plot2d(sin(t),cos(t));
xbasc()
isoview(-1,1,-1,1);
plot2d(sin(t),cos(t),-1,'001');

\end{verbatim}

	\item \verb+square+	: isometric scale with resizing the window

the window is resized according to the parameters of the command.

        \item \verb+scaling+	: scaling on data
        \item \verb+rotate+	: rotation

\verb+scaling+ and \verb+rotate+ executes respectively an affine transform and
a geometric rotation of a 2-lines-matrix corresponding to the {\tt (x,y) }
values of a set of points.
 
        \item \verb+xgetech, xsetech+	: change of scale inside the graphic window

The current graphic scale can be fixed by a high level plot command. You may
want to get this parameter or to fix it directly : this is the role of 
\verb+xgetech, xsetech+ . {\tt xsetech } is a simple way to cut the
window in differents parts for different plots :

\begin{verbatim}

t=(0:0.1:2*%pi)';
xsetech([0.,0.,0.6,0.3],[-1,1,-1,1]);
plot2d(sin(t),cos(t));
xsetech([0.5,0.3,0.4,0.6],[-1,1,-1,1]);
plot2d(sin(t),cos(t));

\end{verbatim}

\end{itemize}
%


\section{2D Plotting}

\subsection{Basic 2D Plotting}

The simplest 2D plot is {\tt plot(x,y)} or {\tt plot(y)}: this is the plot of 
{\tt y} as function of {\tt x} where {\tt x} and {\tt y} are 2 vectors; if 
{\tt x} is missing, it is replaced by the vector {\tt (1,...,size(y))}.
If {\tt y} is a matrix, its rows are plotted. There are optional arguments.


A first example is given by the following commands and one of the results is
represented on figure \ref{d7-1}:

\begin{verbatim}

t=(0:0.05:1)';
ct=cos(2*%pi*t);
// plot the cosine
plot(t,ct);
// xset() opens the toggle panel and 
// some parameters can be changed with mouse clicks
// given by commands for the demo here 
xset("font",5,4);xset("thickness",3);
// plot with captions for the axis and a title for the plot
// if a caption is empty the argument ' ' is needed
plot(t,ct,'Time','Cosine','Simple Plot');
// click on a color of the xset toggle panel and do the previous plot again
// to get the title in the chosen color

\end{verbatim}

\input{figures/d7-1.tex}
\caption{\label{d7-1}First example of plotting}
\end{figure}

\noindent The generic 2D multiple plot is 


\noindent {\tt  plot2di(str,x,y,[style,strf,leg,rect,nax])}
 
\begin{itemize}

\item index of \verb+plot2d+	: {\tt i=missing,1,2,3,4}.

For the different values of {\tt i} we have:

	{\tt i=missing}	: piecewise linear plotting

	{\tt i=1}	: as previous with possible logarithmic scales

	{\tt i=2}	: piecewise constant drawing style

	{\tt i=3}	: vertical bars

	{\tt i=4}	: arrows style (e.g. ode in a phase space)

\end{itemize}

\begin{verbatim}
t=(1:0.1:8)';xset("font",2,3);
xsetech([0.,0.,0.5,0.5],[-1,1,-1,1]);
plot2d([t t],[1.5+0.2*sin(t) 2+cos(t)]);
xtitle('Plot2d');
titlepage('Piecewise linear');
//
xsetech([0.5,0.,0.5,0.5],[-1,1,-1,1]);
plot2d1('oll',t,[1.5+0.2*sin(t) 2+cos(t)]);
xtitle('Plot2d1');
titlepage('Logarithmic scale(s)');
//
xsetech([0.,0.5,0.5,0.5],[-1,1,-1,1]);
plot2d2('onn',t,[1.5+0.2*sin(t) 2+cos(t)]);
xtitle('Plot2d2');
titlepage('Piecewise constant');
//
xsetech([0.5,0.5,0.5,0.5],[-1,1,-1,1]);
plot2d3('onn',t,[1.5+0.2*sin(t) 2+cos(t)]);
xtitle('Plot2d3')
titlepage('Vertical bar plot')
xset('default')
\end{verbatim}

\input{figures/nouv1.tex}
\dessin{Different 2D plotting}{nouv1}

\begin{itemize}

\item Parameter {\tt str}  	: it is the string {\tt "abc"} :
 
	{\tt str} is empty if {\tt i} is missing.

	{\tt a=e} : means empty; the values of {\tt x} are not used;
	   (The user must give a dummy value to {\tt x}).

	{\tt a=o} : means one; the x-values are the same for all the curves

	{\tt a=g} : means general. 

	{\tt b=l} : a logarithmic scale is used on the X-axis

	{\tt c=l} : a logarithmic scale is used on the Y-axis

-Parameters {\tt x,y} : two matrices of the same size {\tt [nl,nc]} ({\tt nc} 
is the number of curves and {\tt nl} is the number of points of each
curve).

For a single curve the vector can be row or column : 
{\tt plot2d(t',cos(t)')  plot2d(t,cos(t))} are equivalent.


\item Parameter {\tt style}  	:it is a real vector of size {\tt
(1,nc)}; the style 
to use for curve j is defined by {\tt size(j)} (when only one curve is drawn 
{\tt style} can specify the style and a position to use for the
caption).

\begin{verbatim}
x=0:0.1:2*%pi;
u=[-0.8+sin(x);-0.6+sin(x);-0.4+sin(x);-0.2+sin(x);sin(x)];
u=[u;0.2+sin(x);0.4+sin(x);0.6+sin(x);0.8+sin(x)]';   
//start trying the color with the 2 following lines
//sty=[-9,-8,-7,-6,-5,-4,-3,-2,-1,0];
//plot2d1('onn',x',u,sty,"111"," ",[0,-2,2*%pi,3],[2,10,2,10]);
plot2d1('onn',x',u,...
  [9,8,7,6,5,4,3,2,1,0],"011"," ",[0,-2,2*%pi,3],[2,10,2,10]);
x=0:0.2:2*%pi; 
v=[1.4+sin(x);1.8+sin(x)]'; 
xset("mark",1,5);
plot2d1('onn',x',v,[7,8],"011"," ",[0,-2,2*%pi,3],[2,10,2,10]);
xset('default');
\end{verbatim}

\input{figures/nouv2.tex}
\dessin{Black and white plotting styles}{nouv2}

\item Parameter {\tt strf}  	: it is a string of length 3 {\tt
"xyz"} corresponding to :

	    {\tt x=1} : captions  displayed 

	    {\tt y=1} : the argument {\tt rect} is used to specify the 
		boundaries of the plot.\\  
		{\tt rect=[xmin,ymin,xmax,ymax]}

	    {\tt y=2}	: the boundaries of the	plot are computed 

	    {\tt y=0}	: the current boundaries 

	    {\tt z=1}	: an axis is drawn and  the number of tics can be specified by the {\tt nax} argument

	    {\tt z=2}	: the plot is only surrounded by a box

\item Parameter {\tt leg } 	 : it is the string of the captions for the different 
plotted curves . This string is composed of fields separated by the {\tt @} 
symbol: for example  {\tt ``module@phase''} (see example below). These 
strings are
displayed under the plot with  small segments recalling the styles of the 
corresponding curves.

\item Parameter {\tt rect } 	: it is a vector of 4 values specifying the boundaries 
of the plot {\tt rect=[xmin,ymin,xmax,ymax]}.

\item Parameter {\tt nax }  	: it is a vector [nx,Nx,ny,Ny] where nx (ny) is 
the number of subgrads on the x (y) axis and Nx (Ny) is the number of 
graduations  on the x (y) axis.

\end{itemize}

\begin{verbatim}

//captions for identifying the curves
//controlling the boundaries of the plot and the tics on axes
x=-%pi:0.3:%pi;
y1=sin(x);y2=cos(x);y3=x;
X=[x;x;x]; Y=[y1;y2;y3];
plot2d1("gnn",X',Y',[1 2 3]',"111","caption1@caption2@caption3",...
[-3,-3,3,2],[2,20,5,5]);

\end{verbatim}

\input{figures/nouv3.tex}
\dessin{Box, captions and tics}{nouv3}

For different plots the simple commands without any argument show a demo 
(e.g {\tt plot2d3()} ).

\subsection{Captions and Presentation}
%
\begin{itemize}
	\item \verb+xgrid+	: adds a grid on a 2D graphic; the
calling parameter is the number of the color.
	\item \verb+xtitle+	: adds	title above the plot and axis 
names on a 2D graphic
	\item \verb+titlepage+	: graphic title page in the middle of
the plot

\begin{verbatim}

//Presentation
x=-%pi:0.3:%pi;
y1=sin(x);y2=cos(x);y3=x;
X=[x;x;x]; Y=[y1;y2;y3];
plot2d1("gnn",X',Y',[1 2 3]',"111","caption1@caption2@caption3",...
[-3,-3,3,2],[2,20,2,5]);
xtitle(["General Title";"(with xtitle command)"],"x-axis title","y-axis title (with xtitle command)");
xgrid();
xclea(-2.7,1.5,1.5,1.5);
titlepage("Titlepage");
xstring(0.6,.45,"(with titlepage command)");
xstring(0.05,.7,["xstring command after";"xclea command"],0,1);

\end{verbatim}

\input{figures/nouv4.tex}
\dessin{Grid, Title eraser and comments}{nouv4}

	\item \verb+plotframe+	: graphic frame with scaling and grid
\end{itemize}
%

We have seen that it is possible to control the tics on the axes,
choose the size of the rectangle for the plotand add a grid.
This operation can be prepared once and then used for a sequence of
different plots. One of the most useful aspect is to get  graduations 
by choosing the number of graduations and getting rounded numbers.

\begin{verbatim}

rect=[-%pi,-1,%pi,1];
tics=[2,10,4,10];
plotframe(rect,tics,[%t,%t],...
['Plot with grids and automatic bounds','angle','velocity']);

\end{verbatim}

\begin{itemize}
	\item \verb+graduate+	: a simple tool for computing pretty
axis graduations before a plot.
\end{itemize}
%

\subsection{Specialized 2D Plottings}
%
\begin{itemize}
        \item \verb+champ+	: vector field in $R^{2}$

\begin{verbatim}
//try champ
x=[-1:0.1:1];y=x;u=ones(x);
fx=x.*.u';fy=u.*.y';
champ(x,y,fx,fy);
xset("font",2,3);
xtitle(['Vector field plot';'(with champ command)']);
//with the color (and a large stacksize)
x=[-1:0.004:1];y=x;u=ones(x);
fx=x.*.u';fy=u.*.y';
champ1(x,y,fx,fy);
\end{verbatim}

\input{figures/nouv5.tex}
\dessin{Vector field in the plane}{nouv5}


	\item \verb+fchamp+	: for a vector field in $R^{2}$ defined by a 
function. The same plot than {\tt champ} for a vector field defined
for example by a scilab program.

	\item \verb+fplot2d+	: 2D plotting of a curve described by a 
function. This function plays the same role for {\tt plot2d} than the 
previous for {\tt champ}.

	\item \verb+grayplot+	: 2D plot of a surface using gray
levels; the surface being defined by the matrix of the values
for a grid.

	\item \verb+fgrayplot+	: the same than the previous for a
surface defined by a function (scilab program).

In fact these 2 functions can be replaced by a usual color plot with
an appropriate colormap where the 3 RGB components are the same.

\begin{verbatim}
R=[1:256]/256;RGB=[R' R' R'];
xset('colormap',RGB);
deff('[z]=surf(x,y)','z=-((abs(x)-1)**2+(abs(y)-1)**2)');
fgrayplot(-1.8:0.02:1.8,-1.8:0.02:1.8,surf,"111",[-2,-2,2,2]);
xset('font',2,3);
xtitle(["Grayplot";"(with fgrayplot command)"]);
//the same plot can be done with a ``unique'' given color
R=[1:256]/256;
G=0.1*ones(R);
RGB=[R' G' G'];
xset('colormap',RGB);
fgrayplot(-1.8:0.02:1.8,-1.8:0.02:1.8,surf,"111",[-2,-2,2,2]);
\end{verbatim}

\input{figures/nouv6.tex}
\dessin{Gray plot with a gray colormap}{nouv6}

	\item \verb+errbar+	: creates a plot with error bars
\end{itemize}
%


\subsection{Plotting Some Geometric Figures}
\subsubsection{Polylines Plotting}
\begin{itemize}
	\item \verb+xsegs+	: draws	a set of unconnected segments 
	\item \verb+xrect+	: draws	a single rectangle
	\item \verb+xfrect+	: fills a single rectangle
	\item \verb+xrects+	: fills or draws a set	of rectangles
	\item \verb+xpoly+	: draws	a polyline
	\item \verb+xpolys+	: draws a set of polylines
	\item \verb+xfpoly+	: fills a polygon
	\item \verb+xfpolys+	: fills a set of polygons
	\item \verb+xarrows+	: draws a set of unconnected arrows
	\item \verb+xfrect+	: fills a single rectangle
	\item \verb+xclea+	: erases a rectangle on a graphic window
\end{itemize}
%

\subsubsection{Curves Plotting}
\begin{itemize}
	\item \verb+xarc+	: draws	an ellipsis
	\item \verb+xfarc+	: fills	an ellipsis
	\item \verb+xarcs+	: fills	or draws a set of ellipsis
\end{itemize}
%

\subsection{ Writting by Plotting}
%
\begin{itemize}
	\item  \verb+xstring+	: draws a string or a matrix of strings
        \item  \verb+xstringl+	: computes a rectangle which surrounds
        a string
	\item  \verb+xstringb+	: draws a string in a specified box
	\item  \verb+xnumb+	: draws a set of numbers
\end{itemize}
%

We give now the sequence of the commands for obtaining the 
figure~ \ref{fgeom}.

\begin{verbatim}
//	initialize default environment variables
xset('default');
xset("use color",0);
plot([1:10]);
xbasc()
xrect(0,1,3,1)
xfrect(3.1,1,3,1)
xstring(0.5,0.5,"xrect(0,1,3,1)")
xstring(4.,0.5,"xfrect(3.1,1,3,1)")
xset("alufunction",6)
xstring(4.,0.5,"xfrect(3.1,1,3,1)")
xset("alufunction",3)
xv=[0 1 2 3 4]
yv=[2.5 1.5 1.8 1.3 2.5]
xpoly(xv,yv,"lines",1)
xstring(0.5,2.,"xpoly(xv,yv,""lines"",1)")
xa=[5 6 6 7 7 8 8 9 9 5]
ya=[2.5 1.5 1.5 1.8 1.8 1.3 1.3 2.5 2.5 2.5]
xarrows(xa,ya)
xstring(5.5,2.,"xarrows(xa,ya)")
xarc(0.,5.,4.,2.,0.,64*300.)
xstring(0.5,4,"xarc(0.,5.,4.,2.,0.,64*300.)")
xfarc(5.,5.,4.,2.,0.,64*360.)
//xset("alufunction",6)
xclea(5.6,4.4,2.8,0.8);
xstring(5.8,4.,"xfarc  and then  xclea")
//xset("alufunction",3)
xstring(0.,4.5,"WRITING-BY-XSTRING()",-22.5) 
xnumb([5.5 6.2 6.9],[5.5 5.5 5.5],[3 14 15],1)
isoview(0,12,0,12)
xarc(-5.,12.,5.,5.,0.,64*360.)
xstring(-4.5,9.25,"isoview + xarc",0.)
xset("font",4,5)
A=["  1" "       2" "  3";"  4" "       5" "  6";"68" "  17.2" "  9"];
xstring(7.,10.,A);
rect=xstringl(7,10,A);
xrect(rect(1),rect(2),rect(3),rect(4));
\end{verbatim}

\input{figures/nouv7.tex}
\dessin{Geometric Graphics and Comments}{fgeom}

e have seen that some parameters of the graphics are controlled by a 
graphic context 
( for example the line thickness) and others are controlled through
graphics arguments . 
%
\begin{itemize}
	\item  {\tt xset}	: to set graphic context values.
Some examples of the use of {\tt xset} : 

(i)-{\tt xset("use color",flag)} changes to color or gray plot according to 
the values (1 or 0) of {\tt flag}.

(ii)-{\tt xset("window",window-number)} sets the current window to the window 
{\tt window-number} and creates the window if it doesn't exist.

(iii)-{\tt xset("wpos",x,y)} fixes the position of the upper left point of 
the graphic window.

The choice of the font, the width and height of the window, the driver...
can be done by {\tt xset}.

	\item  {\tt xget}	: to get informations about the current graphic context.
All the values of the parameters fixed by {\tt xset} can be obtained by 
{\tt xget}.

        \item  {\tt xlfont}	: to load a new family of fonts from the XWindow Manager
\end{itemize}
%
\subsection{Some Classical Graphics for Automatic Control}

\begin{itemize}

	\item  \verb+bode+	: plot magnitude and phase of the 
frequency response of a linear system.

	\item  \verb+gainplot+	: same as bode but plots only the 
magnitude of the frequency response.

	\item  \verb+nyquist+	: plot of imaginary part versus real 
part of the frequency response of a linear system.

	\item  \verb+m_circle+	: M-circle plot used with nyquist plot.

	\item  \verb+chart+	: plot the Nichols'chart 

	\item  \verb+black+	: plot the Black's diagram (Nichols'chart)
for a linear system.  

	\item  \verb+evans+	: plot the Evans root locus for a
linear system.

	\item  \verb+plzr+	: pole-zero plot of the linear system

\end{itemize}

\begin{verbatim}
s=poly(0,'s');
h=syslin('c',(s^2+2*0.9*10*s+100)/(s^2+2*0.3*10.1*s+102.01));
h1=h*syslin('c',(s^2+2*0.1*15.1*s+228.01)/(s^2+2*0.9*15*s+225));
//bode
xsetech([0.,0.,0.5,0.5],[-1,1,-1,1]);
gainplot([h1;h],0.01,100);
//nyquist
xsetech([0.5,0.,0.5,0.5],[-1,1,-1,1]);
nyquist([h1;h])
//chart and black 
xsetech([0.,0.5,0.5,0.5],[-1,1,-1,1]);
black([h1;h],0.01,100,['h1';'h'])
chart([-8 -6 -4],[80 120],list(1,0));
//evans
xsetech([0.5,0.5,0.5,0.5],[-1,1,-1,1]);
H=syslin('c',352*poly(-5,'s')/poly([0,0,2000,200,25,1],'s','c'));
evans(H,100)
\end{verbatim}

\input{figures/nouv8.tex}
\dessin{Some Plots in Automatic Control}{nouv8}

%
\subsection{Miscellaneous}
%
\begin{itemize}
	\item  \verb+edit_curv+ : interactive graphic curve editor.

	\item  \verb+gr_menu+ 	: simple interactive graphic editor. It
is a Xfig-like simple editor with a flexible use for a nice
presentation of graphics : the user can superpose the elements of
\verb+gr_menu+ and use it with the usual possibilities of {\tt xset}.

	\item  \verb+locate+ 	: to get the coordinates of one or more 
points selected with the mouse on a graphic window.

\end{itemize}
% 

\begin{verbatim}

\end{verbatim}
\input{figures/scifi2.tex}
\dessin{Presentation of Plots}{scifi2}


\section{3D Plotting}
\subsection{Generic 3D Plotting}
%
\begin{itemize}
	\item  \verb+plot3d+ : 3D plotting of a matrix of points : plot3d(x,y,z) with x,y,z 3 matrices, z being the values for the points with coordinates x,y. Other
arguments are optional
	\item   \verb+plot3d1+ : 3d plotting	of a matrix of points with gray levels
	\item   \verb+fplot3d+ : 3d plotting	of a surface described by a function; z is given by an external z=f(x,y)
	\item   \verb+fplot3d1+ : 3d	plotting of a surface described	by a function with gray	levels
\end{itemize}
%
 
\subsection{Specialized 3D Plotting}
\begin{itemize}
	\item \verb+param3d+	: plots parametric curves in 3d space
	\item \verb+contour+	: level curves for a 3d function given by a 
matrix
	\item \verb+grayplot10+ : gray level on a 2d plot
	\item \verb+fcontour10+ : level curves for a 3d function given by a 
function
	\item \verb+hist3d+	: 3d histogram
	\item \verb+secto3d+	: conversion of a surface description from 
sector to plot3d compatible data
	\item \verb+eval3d+	: evaluates a function on a regular grid. 
(see also feval)
\end{itemize}
%
 

\subsection{Mixing 2D and 3D graphics}

When one uses 3D plotting function, default graphic boundaries are
fixed, but in $R^3$. If one wants to use graphic primitives 
to add informations on 3D graphics, the \verb+geom3d+ function can be
used to convert 3D coordinates to 2D-graphics coordinates. The
figure~ \ref{d710} illustrates this feature.

%\def\exemple{d710}
\input{figures/d7-10.vtex}

\input{figures/d710.tex}
\dessin{2D and 3D plot}{d710}

\subsection{Sub-windows}
%\def\exemple{d7-8}

It is also possible to make multiple plotting in the same 
graphic window (Figure~\ref{d7-8}).

\input{figures/d7-8.vtex}

\input{figures/d7-8.tex}
\caption{\label{d7-8}Use of xsetech}
\end{figure}


\subsection{A Set of Figures}
%\def\exemple{d7a11}

In this next example we give a brief summary of different plotting
functions for 2D or 3D graphics. The figure~ \ref{d7a11} is 
obtained and inserted in this document with the help of the command 
\verb+Blatexprs+.
 
\input{figures/d7a11.vtex}

\input{figures/d7a11.tex}
\caption{\label{d7a11}Group of figures}
\end{figure}

\section{Printing and Inserting Scilab Graphics in \LaTeX}

We describe here the use of programs (Unix shells) for handling Scilab 
graphics and printing the results. These programs are located in the
sub-directory {\tt bin} of Scilab.

\subsection{Window to Paper}
The simplest command to get a paper copy of a plot is to click on the
{\tt print} button of the ScilabGraphic window.

\subsection{Creating a Postscript File}
We have seen at the beginning of this chapter that the simplest way to get 
a Postscript file containing a Scilab plot is :

\begin{verbatim}
-->driver('Pos')
 
-->xinit('foo.ps')
 
-->plot3d1();
 
-->xend()
 
-->driver('Rec')
 
-->plot3d1()
 
-->xbasimp(0,'foo1.ps')

\end{verbatim}


The Postscript files ({\tt foo.ps } or {\tt foo1.ps }) generated by Scilab 
cannot be directly sent to a
Postscript printer, they need a preamble. Therefore, printing is done
through the use of Unix scripts or programs which are provided with
Scilab. The program \verb+Blpr+ is used to print a set of Scilab Graphics 
on a single sheet of paper and is used as follows~:

\begin{verbatim}
 Blpr string-title file1.ps file2.ps > result
\end{verbatim}

You can then print the file  {\tt result} with the classical Unix command :

\begin{verbatim}
lpr -Pprinter-name result
\end{verbatim}

\noindent or use the \verb+ghostview+ Postscript interpreter on your Unix
workstation to see the result.

You can avoid the file {\tt result} with a pipe, replacing {\tt  > result}
by the printing command {\tt | lpr} or the previewing command 
{\tt | ghostview -}.

The best result (best sized figures) is obtained when printing two 
pictures on a single page. 


\subsection{Including a Postscript File in \LaTeX}

The \verb|Blatexpr| Unix shell and the programs \verb+Batexpr2+ and 
\verb+Blatexprs+ are provided in order to help inserting Scilab graphics 
in \LaTeX .

Taking the previous file {\tt foo.ps} and  typing the following statement 
under a Unix shell~:
\begin{verbatim}
Blatexpr 1.0 1.0 foo.ps
\end{verbatim}
creates two files \verb+foo.epsf+ and \verb+foo.tex+. The original
Postscript file is left unchanged. 
To include the figure in a \LaTeX~ document you should insert the following 
\LaTeX~ code in your \LaTeX~ document~:

\begin{verbatim}
\input foo.tex
\dessin{The caption of your picture}{The-label}
\end{verbatim}

You can also see your figure by using  the  Postscript
previewer \verb+ghostview+.

The program \verb+Blatexprs+ does the same thing: it is used to insert
a set of Postscript figures in one \LaTeX picture.

In the following example, we begin by using the Postscript driver {\tt Pos}
and then initialize successively 4 Postscript files 
{\tt fig1.ps, ..., fig4.ps} for
4 different plots and at the end return to the driver {\tt Rec} (X11 driver
with record).

\input{diary/mulplot.dia}

Then we execute the command :

\begin{verbatim}
  Blatexprs multi fig1.ps fig2.ps fig3.ps fig4.ps
\end{verbatim}

\noindent and we get 2 files {\tt multi.tex} and  {\tt multi.ps} and you can 
include the result in a \LaTeX~ source file by :

\begin{verbatim}
\input multi.tex
\dessin{The caption of your picture}{The-label}
\end{verbatim}

Note that the second line {\tt dessin...} is absolutely necessary and you
have of course to give the absolute path for the input file if you are 
working in another directory (see below). The file {\tt  multi.tex} is only 
the definition of the command {\tt dessin} with 2 parameters : the caption 
and the label; the command {\tt dessin} can be used with one or two
empty arguments {\tt `` ``} if you want to avoid the caption or the label.   

The Postscipt files are inserted in \LaTeX~ with the help of the
\verb+\special+ command and with a syntax that works with the
\verb+dvips+ program.

The program \verb+Blatexpr2+ is used when you want two pictures side
by side.
\begin{verbatim}
  Blatexpr2 Fileres file1.ps file2.ps 
\end{verbatim}

%\def\exemple{d7-12}
\input{figures/d7-12.tex}
\caption{\label{d7-12}Blatexp2 Example}
\end{figure}

It is sometimes convenient to have a main \LaTeX~ document in a directory
and to store all the figures in a subdirectory. The proper way to
insert a  picture file in the main document, when the picture 
is stored in the subdirectory \verb+figures+, is the following~:

\begin{verbatim}
\def\Figdir{figures/} % My figures are in the {\tt figures/ } subdirectory.
\input{figures/fig.tex}
\dessin{The caption of you picture}{The-label}
\end{verbatim}

The declaration \verb+\def\Figdir{figures/}+ is used twice, first to
find the file {\tt fig.tex} (when you use \verb+latex+), and
 second to produce a correct pathname for the
\verb+special+ \LaTeX~ command  found in \verb+fig.tex+. (used at
dvips level).

-WARNING : the default driver is {\tt Rec}, i.e. all the graphic commands are
recorded, one record corresponding to one window. The {\tt xbasc()} command
erases the plot on the active window and all the records corresponding to
this window. The {\tt  clear} button has the same effect; the {\tt xclear}
command erases the plot but the record is preserved. So you almost never need
to use the {\tt xbasc()} or {\tt  clear} commands. If you use such a command 
and if you re-do a plot you may have a surprising result (if you forget
that the environment is wiped out); the scale only is preserved and so you 
may have the ``window-plot'' and the ``paper-plot'' completely different.


\subsection{Postscript by Using Xfig}

Another useful way to get a Postscript file for a plot is to use Xfig.
By the simple command {\tt xs2fig(active-window-number,file-name)} you get
a file in Xfig syntax. 

This command needs the use of the driver {\tt Rec}.

The window ScilabGraphic0 being  active, if you enter :

\begin{verbatim}

-->t=-%pi:0.3:%pi;
 
-->plot3d1(t,t,sin(t)'*cos(t),35,45,'X@Y@Z',[2,2,4]);
 
-->xs2fig(0,'demo.fig');   

\end{verbatim}

you get the file {\tt demo.fig} which contains the plot 
of window 0. 

Then you can use Xfig and after the modifications you want, get a Postscript 
file that you can insert in a \LaTeX~ file. The following figure is the result
of Xfig after adding some comments.

\begin{figure}
\fbox{\hspace*{0.cm} \begin{picture}(400.0,350.0)(100.0,200.0)
\hspace{-0.8cm}
\special{psfile=figures/demo.ps}
\end{picture}}
\caption{Encapsulated Postscript by Using Xfig}
\label{xfig2ps}
\end{figure}


\subsection{Encapsulated Postscript Files}
As it was said before, the use of {\tt Blatexpr} creates 2 files : a 
{\tt .tex} file to be inserted in the \LaTeX~ file and a {\tt .epsf} file.

It is possible to get the encapsulated Postscript file corresponding to a 
{\tt .ps} file by using the command {\tt BEpsf}.

Notice that the {\tt .epsf} file generated by {\tt Blatexpr} is not an 
encapsulated Postscript file : it has no bounding box and {\tt BEpsf}
generates a {\tt .eps} file which is an encapsulated Postscript file with 
a bounding box.