Next: Specialized Two-Dimensional Plots, Up: Plotting

### 16.1 Two-Dimensional Plotting

The basic plotting commands are:

— Function File: axes ()
— Function File: axes (property, value, ...)
— Function File: axes (h)

> Create an axes object and return a handle to it.

— Function File: plot (args)

> This function produces two-dimensional plots. Many different combinations of arguments are possible. The simplest form is

>               plot (y)

> where the argument is taken as the set of y coordinates and the x coordinates are taken to be the indices of the elements, starting with 1.

> To save a plot, in one of several image formats such as PostScript or PNG, use the `print` command.

> If more than one argument is given, they are interpreted as

>               plot (x, y, fmt, ...)

> or as

>               plot (x, y, property, value, ...)

> where y, fmt, property and value are optional, and any number of argument sets may appear. The x and y values are interpreted as follows:

> - If a single data argument is supplied, it is taken as the set of y coordinates and the x coordinates are taken to be the indices of the elements, starting with 1.
> - If the x is a vector and y is a matrix, then the columns (or rows) of y are plotted versus x. (using whichever combination matches, with columns tried first.)
> - If the x is a matrix and y is a vector, y is plotted versus the columns (or rows) of x. (using whichever combination matches, with columns tried first.)
> - If both arguments are vectors, the elements of y are plotted versus the elements of x.
> - If both arguments are matrices, the columns of y are plotted versus the columns of x. In this case, both matrices must have the same number of rows and columns and no attempt is made to transpose the arguments to make the number of rows match.

>   If both arguments are scalars, a single point is plotted.

> If the fmt argument is supplied, it is interpreted as follows. If fmt is missing, the default gnuplot line style is assumed.

> ``-`'
>   Set lines plot style (default).
> ``.`'
>   Set dots plot style.
> ``^`'
>   Set impulses plot style.
> ``L`'
>   Set steps plot style.
> ``n`'
>   Interpreted as the plot color if n is an integer in the range 1 to 6.
> ``nm`'
>   If nm is a two digit integer and m is an integer in the range 1 to 6, m is interpreted as the point style. This is only valid in combination with the `@` or `-@` specifiers.
> ``c`'
>   If c is one of `"k"` (black), `"r"` (red), `"g"` (green), `"b"` (blue), `"m"` (magenta), `"c"` (cyan), or `"w"` (white), it is interpreted as the line plot color.
> ``";title;"`'
>   Here `"title"` is the label for the key.
> ``+`'
> ``*`'
> ``o`'
> ``x`'
>   Used in combination with the points or linespoints styles, set the point style.

> The color line styles have the following meanings on terminals that support color.

>               Number  Gnuplot colors  (lines)points style
>                 1       red                   *
>                 2       green                 +
>                 3       blue                  o
>                 4       magenta               x
>                 5       cyan                house
>                 6       brown            there exists

> The fmt argument can also be used to assign key titles. To do so, include the desired title between semi-colons after the formatting sequence described above, e.g. "+3;Key Title;" Note that the last semi-colon is required and will generate an error if it is left out.

> If a property is given it must be followed by value. The property value pairs are applied to the lines drawn by `plot`.

> Here are some plot examples:

>               plot (x, y, "@12", x, y2, x, y3, "4", x, y4, "+")

> This command will plot `y` with points of type 2 (displayed as ``+`') and color 1 (red), `y2` with lines, `y3` with lines of color 4 (magenta) and `y4` with points displayed as ``+`'.

>               plot (b, "*", "markersize", 3)

> This command will plot the data in the variable `b`, with points displayed as ``*`' with a marker size of 3.

>               t = 0:0.1:6.3;
>               plot (t, cos(t), "-;cos(t);", t, sin(t), "+3;sin(t);");

> This will plot the cosine and sine functions and label them accordingly in the key.

> See also: semilogx, semilogy, loglog, polar, mesh, contour, __pltopt__ bar, stairs, errorbar, xlabel, ylabel, title, print.

— Function File: line ()
— Function File: line (x, y)
— Function File: line (x, y, z)
— Function File: line (x, y, z, opts)

> Create line object from x and y and insert in current axes object. Return handle to line object.

— Function File: fplot (fn, limits)
— Function File: fplot (fn, limits, tol)
— Function File: fplot (fn, limits, n)
— Function File: fplot (..., LineSpec)

> Plot a function fn, within the defined limits. fn an be either a string, a function handle or an inline function. The limits of the plot are given by limits of the form `[`xlo`,` xhi`]` or `[`xlo`,` xhi`,` ylo`,` yhi`]`. tol is the default tolerance to use for the plot, and if tol is an integer it is assumed that it defines the number points to use in the plot. The LineSpec is passed to the plot command.

>                  fplot ("cos", [0, 2*pi])
>                  fplot ("[cos(x), sin(x)]", [0, 2*pi])

> See also: plot.

— Function File: drawnow ()

> Display the current graphics.

— Function File: shg

> Show the graph window. Currently, this is the same as executing `drawnow`.

> See also: plot, semilogx, semilogy, loglog, polar, mesh, contour, bar, stairs, xlabel, ylabel.

— Function File: hold args

> Tell Octave to `hold' the current data on the plot when executing subsequent plotting commands. This allows you to execute a series of plot commands and have all the lines end up on the same figure. The default is for each new plot command to clear the plot device first. For example, the command

>               hold on

> turns the hold state on. An argument of `"off"` turns the hold state off, and `hold` with no arguments toggles the current hold state.

— Function File: ishold

> Return 1 if the next line will be added to the current plot, or 0 if the plot device will be cleared before drawing the next line.

— Function File: newplot ()