Octave Programming Tutorial/Plotting
From Wikibooks, the open-content textbooks collection
WARNING: This page is still under heavy construction
Contents |
[edit] 2D plots
plot(y)
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.
plot(x, y)
- If the first argument is a vector and the second is a matrix, 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 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.
[edit] Example
x = linspace(0, 2*pi, 100); y = sin(x); plot(x, y);
[edit] Non-linear plots
semilogx, semilogy, loglog, polar
[edit] Formatting
`-'
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 `"r"', `"g"', `"b"', `"m"', `"c"', or `"w"',
it is interpreted as the plot color (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 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.
[edit]
xlabel, ylabel, and title, replot
[edit] 3D plots
mesh, meshgrid, surf
[edit] Contour plots
contour
[edit] Images
colormap, image, imshow, hsv2rgb
[edit] Saving and printing graphs
Print a graph to a printer or save it to a file
print("-Pprinter")
print("filename", "-ddevice")
Devices:
`ps'
`ps2'
`psc'
`psc2'
Postscript (level 1 and 2, mono and color)
`eps'
`eps2'
`epsc'
`epsc2'
Encapsulated postscript (level 1 and 2, mono and color)
`ill'
`aifm'
Adobe Illustrator
`cdr'
`corel'
CorelDraw
`hpgl'
HP plotter language
`fig'
XFig
`dxf'
AutoCAD
`mf'
Metafont
`png'
Portable network graphics
`pbm'
PBMplus
If the device is omitted, it is inferred from the file extension, or if there is no filename it is sent to the printer as postscript.
Return to the Octave Programming tutorial index