Next: Specialized Two-Dimensional Plots, Up: Plotting
The basic plotting commands are:
Create an axes object and return a handle to it.
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
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, the 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 existsThe 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) andy4
with points displayed as `+'.plot (b, "*", "markersize", 3)This command will plot the data in the variable
b
will be plotted 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.
Create line object from x and y and insert in current axes object. Return handle to line object.
Plots 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]
. n is the number of points to use and defaults to 100.fplot('cos',[0,2*pi]) fplot('[cos(x),sin(x)]',[0,2*pi])
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.
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 onturns the hold state on. An argument of
"off"
turns the hold state off, andhold
with no arguments toggles the current hold state.