Algo

Páginas: 11 (2583 palabras) Publicado: 12 de abril de 2012
EGR 423 W’01
Scilab PLOT2D Tutorial
Scilab’s plotting facilities are hard to use. This tutorial is intended to guide your way through the
plot2d range of functions. Note that an easier-to-use alternative exists in the form of a thirdparty contributed package known as plotlib. It must be installed as an add-on to Scilab. You
can get plotlib from:
http://www.dma.utc.fr/~mottelet/myplot.htmlThe goal behind plotlib is to present a MATLAB-like interface to plotting for Scilab. This is,
in my opinion, an easier-to-use interface to the same functionality. However, it is still important to
know of Scilab’s basic plotting functionality. If you do use plotlib and it doesn’t behave the
way you want it to, you will need to revert to Scilab’s functions.

1.0 PLOT
The simplest Scilabfunction for plotting a vector of data is plot since you can simply say:
plot(y)
and the data in the vector y is plotted on the Y-axis against the numbers 1 through N (where
N=length(y)) on the X-axis.
For control over the numbers on the X-axis you can write:
plot(x,y)
and now the vector y is plotted against the vector x. Finally, you can add a caption for both the Xaxis, Y-axis, and the title ofthe plot:
plot(x, y, ‘x axis label’, ‘y axis label’, ‘title of plot’)

2.0 PLOT2D
The plot2d function must be used when plot is insufficient. That is, plot2d provides the
following additional options for controlling the appearance of a plot:






Multiple vectors may be plotted at the same time
Line styles and colors may be specified
A legend may be displayed
The axes mayhave their bounds set manually
Whether or not axes are drawn and how tick-marks appear on the axes

1

2.1 Plotting multiple vectors
Multiple sets of (x,y) vectors may be plotted by putting all X-axis vectors as column vectors into
one matrix X and all Y-axis vectors as column vectors into another matrix Y. For example:
x = (0:0.1:10)’;

//
//
y1 = sin(x);
//
y2 = cos(x);
//plot2d([x, x], [y1, y2]);

X axis for both curves. Note that it
MUST BE A COLUMN VECTOR, hence the ’
First vector to plot
Second vector to plot

The first parameter to plot2d is an NxP matrix comprising the set of X-axis column vectors
(which will most likely all be the same thing), where N is the number of points to plot and P is the
number of vectors that you will be plotting at the same time.The second parameter to plot2d is also an NxP matrix comprising the set of Y-axis column vectors. The most common error with the plot2d family of functions is forgetting the required column vector format.
Note the following:


The range construct 0:0.1:10 (for example) constructs row vectors. This must be
transposed to form a column vector (e.g., (0:0.1:10)’).



Scalar functions thatcan operate over vectors (e.g., sin(), cos(), etc.) return a
result that is the same shape as their argument. So sin(x) is a row vector if x is a
row vector and sin(x) is a column vector if x is a column vector.



Column vectors are pasted into a single matrix using commas:
[column1, column2, column3]

2.2 Line styles and colors
The optional third parameter to plot2d is a 1xP rowvector describing how each one of the P
curves should be plotted:


Values less than or equal to 0 draw unconnected points rather than a connected curve. The
types of points to draw (known as marker style) is given by the number:
0 : ‘.’
-1 : ‘+’
-2 : ‘X’
-3 : ‘*’
-4 : Filled diamonds
-5 : Unfilled ovals
-6 : ′ ⊗ ′
-7 : ‘ ∇ ’
-8 : Clubs (known as trefle in the documentation)
-9 : ‘o’2

Marker styles below -9 are drawn as style -9.


Values greater than 0 indicate a line color (1: black, 2: blue, 3: green, etc.)

For example, let us plot the sin and cos curves from a previous example using different colors:
x = (0:0.1:10)’;

// X axis for both curves. Note that it
// MUST BE A COLUMN VECTOR, hence the ’
y1 = sin(x);
// First vector to plot
y2 = cos(x);
//...
Leer documento completo

Regístrate para leer el documento completo.

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS