Line and Scatter Plots
The following mathlayer® functions are used to generate two dimensional line and scatter plots:
In the case of a single matrix argument, each column of the matrix will be plotted with a different colour:
In the case of a table argument, the table's first column will be used for the x-axis coordinates against
which all other columns will be plotted and a legend is automatically added with the table's variable names:
Using two input arguments x and y, the argument x will be used as the x-axis coordinates against which y values will be plotted:
- scatter: each point in the graph is represented by a circle
- plot: the graph's points are connected by a line
- stem: for discrete data
- plotyy: plot with secondary axis
Defining Coordinates
Using a single vector argument will automatically use the vector 1:n as x-axis coordinates, where n denotes the vector's size:y = [1 4 2 3] plot(y)% plotting a single vector
y = [1 4 2 3; 2 5 1 6] plot(y)% plotting matrix y
t = table([1;2;3;4],[3;7;5;2],[7;2;6;4],'VariableNames',{'x','line1','line2'}) plot(t)% plotting table t
- y can be a vector with the same number of elements as x
- y can be a matrix with with one of its dimensions equal to the length of x
x = [1 3 4 7] y = [4 2 7 4;6 5 4 7;3 3 2 5] plot(x,y)
Secondary Axis
plotyy function allows to use a secondary axis:x = [1 3 4 7] y1 = [4 1 7 4] y2 = [60 50 40 70] plotyy(x, y1, x, y2)% using secondary axis
Scatter Plots
Plot a graph with circles in the positions specified by X and Y.y = rand(10, 5) scatter(y)% scatter plotting 5 vectors of uniform random values
Discrete Data
stem function helps visualizing discrete data sequences:y = linspace(-2*pi,2*pi,10) stem(y)% using stem for discrete linear data sequence