MATLAB can produce both planar plots and 3-D mesh surface plots.
To preview some of these capabilities in version 3.5, enter the
command `plotdemo`.

**Planar plots.**
The `plot` command creates linear x-y plots;
if `x` and `y` are vectors of
the same length, the command `plot(x,y)` opens a graphics window and draws
an x-y plot of the elements of `x` versus the elements of `y`.
You can, for
example, draw the graph of the sine function over the interval -4 to 4 with
the following commands:

Try it. The vectorx = -4:.01:4; y = sin(x); plot(x,y)

When in the graphics screen, pressing any key will return you to the command
screen while the command `shg` (show graph) will then return you to the
current graphics screen. If your machine supports multiple windows with a
separate graphics window, you will want to keep the graphics window
exposed-but moved to the side-and the command window active.

As a second example, you can draw the graph of over the interval -1.5 to 1.5 as follows:

Note that one must precede the power-to sign by a period to ensure that it operates entrywise (see section 3).x = -1.5:.01:1.5; y = exp(-x.^2); plot(x,y)

Plots of parametrically defined curves can also be made. Try, for example,

t=0:.001:2*pi; x=cos(3*t); y=sin(2*t); plot(x,y)

The command `grid` will place grid lines on the current graph.

The graphs can be given titles, axes labeled, and text placed within the graph with the following commands which take a string as an argument.

For example, the commandtitle graph title xlabel x-axis label ylabel y-axis label gtext interactively-positioned text text position text at specified coordinates

gives a graph a title. The commandtitle('Best Least Squares Fit')

By default, the axes are auto-scaled. This can be overridden by the command
`axis`. If is a 4-element
vector, then `axis(c)` sets the axis scaling to the precribed limits.
By itself, `axis` freezes the current scaling for subsequent graphs;
entering `axis` again returns to auto-scaling.
The command `axis('square')` ensures that the same scale is used on both
axes. In version 4.0, `axis` has been significantly changed; see
help axis.

Two ways to make multiple plots on a single graph are illustrated by

and by forming a matrixx=0:.01:2*pi;y1=sin(x);y2=sin(2*x); y3=sin(4*x);plot(x,y1,x,y2,x,y3)

Another way is withx=0:.01:2*pi; Y=[sin(x)', sin(2*x)', sin(4*x)']; plot(x,Y)

One can override the default linetypes and pointtypes. For example,

renders a dashed line and dotted line for the first two graphs while for the third the symbol is placed at each node. The line- and mark-types arex=0:.01:2*pi; y1=sin(x); y2=sin(2*x); y3=sin(4*x); plot(x,y1,'--',x,y2,':',x,y3,'+')

Linetypes: solid (`-`), dashed (`-`). dotted (`:),
dashdot ( -.)
`

`
Marktypes: point ( .), plus (), star (*),
circle (o), x-mark (x)
`

`
See help plot for line and mark colors.
`

`
The command subplot can be used to partition the screen so that
up to four plots can be viewed simultaneously. See help subplot.
`

`
Graphics hardcopy Note that most of this section is no longer relevant
`

`
A hardcopy of the graphics screen can be most easily obtained with the MATLAB
command print. It will send a high-resolution copy of the current
graphics screen to the printer, placing the graph on the top half of the page.
`

`
In version 4.0 the meta and gpp commands described below have been
absorbed into the print command. See help print.
`

`
Producing unified hard copy of several plots requires more effort. The Matlab
command meta filename stores the current graphics screen in a file
named filename.met (a ``metafile'') in the current directory. Subsequent
meta (no filename) commands append a new current graphics screen to
the previously named metafile. This metafile-which may now contain several
plots-may be processed later with the graphics post-processor (GPP) program
to produce high-resolution hardcopy, two plots per page.
`

`
The program GPP (graphics post-processor) is a system command, not
a MATLAB command. However, in practice it is usually involked from within
MATLAB using the "!" feature (see section 14). It acts on a device-independent metafile to produce an output file appropriate for many different
hardcopy devices.
`

`
The selection of the specific hardcopy device is made with
the option key " /d". For example, the system commands
`

gpp filename /dps gpp filename /djet

*Note that in newer versions of Matlab the above text is no longer relevant*

**3-D mesh plots.**
Three dimensional mesh surface plots are drawn with the function `mesh`.
The command `mesh(z)` creates a three-dimensional perspective plot of the
elements of the matrix `z`. The mesh surface is defined by the z-coordinates
of points above a rectangular grid in the x-y plane. Try `mesh(eye(10))`.

To draw the graph of a function `z=f(x,y)` over a rectangle, one first
defines vectors `xx` and `yy` which give partitions
of the sides of the
rectangle. With the function `meshdom` (mesh domain; called `meshgrid` in version 4.0) one then creates
a matrix `x`, each row of which equals `xx`
and whose column length is the
length of `yy`, and similarly a matrix `y`, each
column of which equals `yy`,
as follows:

One then computes a matrix[x,y] = meshdom(xx,yy);

You can, for example, draw the graph of over the square
`[-2,2] x [-2,2] ` as follows (try it):

One could, of course, replace the first three lines of the preceding withxx = -2:.1:2; yy = xx; [x,y] = meshdom(xx,yy); z = exp(-x.^2 - y.$^2); mesh(z)

[x,y] = meshdom(-2:.1:2, -2:.1:2);

You are referred to the User's Guide for further details regarding `mesh`.

In version 4.0, the 3-D graphics capabilities of MATLAB have been
considerably expanded. Consult the on-line help for `plot3, mesh`,
and `surf`.

Wed Mar 13 19:15:55 MET 1996