Next: Specialized Two-Dimensional Plots, Up: Plotting
The Matlab-style two-dimensional plotting commands are:
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.
If more than one argument is given, they are interpreted as
plot (x, y, fmt ...)where y and fmt 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 first argument is a vector and the second is a matrix, the the vector is plotted versus the columns (or rows) of the matrix. (using whichever combination matches, with columns tried first.)
- If the first argument is a matrix and the second is a vector, the the columns (or rows) of the matrix are plotted versus the vector. (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 points plot style.
- `-@'
- Set linespoints 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"
,"r"
,"g"
,"b"
,"m"
,"c"
, or"w"
, it is interpreted as the plot color (black, red, green, blue, magenta, cyan, or white).- `";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.
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, "*")This command will plot the data in the variable
b
will be plotted with points displayed as `*'.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, replot, xlabel, ylabel, title.
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.
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.
Clear the plot window and any titles or axis labels. The name
clg
is aliased toclearplot
for compatibility with Matlab.
Show the graph window. Currently, this is the same as executing replot.
See also: plot, semilogx, semilogy, loglog, polar, mesh, contour, bar, stairs, replot, xlabel, ylabel.
Close stream to the
gnuplot
subprocess. If you are using X11, this will close the plot window.
Delete the temporary files created by the plotting commands.
Octave creates temporary data files for
gnuplot
and then sends commands tognuplot
through a pipe. Octave will delete the temporary files on exit, but if you are doing a lot of plotting you may want to clean up in the middle of a session.A future version of Octave will eliminate the need to use temporary files to hold the plot data.
Set axis limits for plots.
The argument limits should be a 2, 4, or 6 element vector. The first and second elements specify the lower and upper limits for the x axis. The third and fourth specify the limits for the y axis, and the fifth and sixth specify the limits for the z axis.
Without any arguments,
axis
turns autoscaling on.With one output argument,
x=axis
returns the current axes (this is not yet implemented for automatic axes).The vector argument specifying limits is optional, and additional string arguments may be used to specify various axis properties. For example,
axis ([1, 2, 3, 4], "square");forces a square aspect ratio, and
axis ("labely", "tic");turns tic marks on for all axes and tic mark labels on for the y-axis only.
The following options control the aspect ratio of the axes.
"square"
- Force a square aspect ratio.
"equal"
- Force x distance to equal y-distance.
"normal"
- Restore the balance.
The following options control the way axis limits are interpreted.
"auto"
- Set the specified axes to have nice limits around the data or all if no axes are specified.
"manual"
- Fix the current axes limits.
"tight"
- Fix axes to the limits of the data (not implemented).
The option
"image"
is equivalent to"tight"
and"equal"
.The following options affect the appearance of tic marks.
Note, if there are no tic marks for an axis, there can be no labels.
"on"
- Turn tic marks and labels on for all axes.
"off"
- Turn tic marks off for all axes.
"tic[xyz]"
- Turn tic marks on for all axes, or turn them on for the specified axes and off for the remainder.
"label[xyz]"
- Turn tic labels on for all axes, or turn them on for the specified axes and off for the remainder.
"nolabel"
- Turn tic labels off for all axes.
The following options affect the direction of increasing values on the axes.
"ij"
- Reverse y-axis, so lower values are nearer the top.
"xy"
- Restore y-axis, so higher values are nearer the top.