## 5.4.1 Basic 2D Plotting

The simplest 2D plot is plot(x,y) or plot(y): this is the plot of y as function of x where x and y are 2 vectors; if x is missing, it is replaced by the vector (1,size(y,'*'))). If 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 5.1:

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


The generic 2D multiple plot is

plot2di(x,y,<options>)

• index of plot2d : i=missing,2,3,4.

For the different values of i we have:

i=missing : piecewise linear/logarithmic plotting

i=2 : piecewise constant drawing style

i=3 : vertical bars

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

t=(1:0.1:8)';xset("font",2,3);
subplot(2,2,1)
plot2d([t t],[1.5+0.2*sin(t) 2+cos(t)]);
xtitle('Plot2d-Piecewise linear');
//
subplot(2,2,2)
plot2d(t,[1.5+0.2*sin(t) 2+cos(t)],logflag='ll');
xtitle('Plot2d1-Logarithmic scales');
//
subplot(2,2,3)
plot2d2(t,[1.5+0.2*sin(t) 2+cos(t)]);
xtitle('Plot2d2-Piecewise constant');
//
subplot(2,2,4)
plot2d3(t,[1.5+0.2*sin(t) 2+cos(t)]);
xtitle('Plot2d3-Vertical bar plot')


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

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

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

xmax=5.;x=0:0.1:xmax;
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 symbols (negative values for the style)

plot2d(x,u,style=[-9,-8,-7,-6,-5,-4,-3,-2,-1,0])

x=0:0.2:xmax;
v=[1.4+sin(x);1.8+sin(x)]';
xset("mark size",5);
plot2d(x,v,style=[-7,-8])
xset('default');


• Option frameflag : is a scalar corresponding to :

 requirements ranges ranges ranges of a previous given by computed from actual plot rect arg x and y requested one 0 1 2 Computed for isometric 3 4 view Enlarged For pretty 5 6 axes Previous and current 7 8 plots merged

• Option axesflag controls the display of information on the frame around the plot :
• 0 : nothing is drawn around the plot.
• 1 : axes are drawn, the y=axis is displayed on the left.
• 2 : the plot is surrounded by a box without tics.
• 3 : axes are drawn, the y=axis is displayed on the right.
• 4 : axes are drawn centred in the middle of the frame box.

• 5 : axes are drawn so as to cross at point (0,0). If point (0,0) does not lie inside the frame, axes will not appear on the graph.

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

• Option rect : it is a vector of 4 values specifying the boundaries of the plot rect=[xmin,ymin,xmax,ymax].

• Option 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.

//captions for identifying the curves
//controlling the boundaries of the plot and the tics on axes
x=-5:0.1:5;
y1=sin(x);y2=cos(x);
X=[x;x]; Y=[y1;y2];
plot2d(X',Y',style=[-1 -3]',leg="caption1@caption2",...
rect=[-5,-1,5,1],nax=[2,10,5,5]);


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