Octave 程式設計教程/繪圖
Octave 可以與 gnuplot、Grace、PLplot 協同工作。一些人認為 PLplot 是 Octave 中傳統 gnuplot 的替代品。
plot(y)
如果只提供一個數據引數,它將被視為 Y 座標集,而 X 座標將被視為元素的索引,從 1 開始。
plot(x, y)
- 如果第一個引數是向量,第二個引數是矩陣,則向量將相對於矩陣的列(或行)繪製。(使用匹配的組合,首先嚐試列。)
- 如果第一個引數是矩陣,第二個引數是向量,則矩陣的列(或行)將相對於向量繪製。(使用匹配的組合,首先嚐試列。)
- 如果兩個引數都是向量,則 Y 的元素將相對於 X 的元素繪製。
- 如果兩個引數都是矩陣,則 Y 的列將相對於 X 的列繪製。在這種情況下,兩個矩陣必須具有相同數量的行和列,並且不會嘗試轉置引數以使行數匹配。
linspace(b, l, n)
將生成一個包含 b 和 l 之間 n 個線性間隔數字的向量。它經常用於在 plot 的雙引數形式中生成向量 X。

x = linspace(0, 10, 100);
y = sin(x);
plot(x, y);
semilogx、semiology、loglog、polar
可以使用附加的 FMT 引數對繪圖進行格式化。
plot (x, [y,] FMT, …)
在引數中,可以出現以下任何選項
`-'
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 white 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.
此外,還可以同時將一組屬性-值對應用於 plot 繪製的每條“線”。
plot (x, [y,] FMT, property, value, …)
這裡我們不在圖形上繪製線,而是為每個資料點放置一個 '+' 標記,選擇第一個顏色(紅色),並新增圖例。
x = linspace(0, 2*pi, 50);
y = sin(x);
plot(x, y, '+1;sin(x);');
第二個示例添加了另一條線以及一些屬性-值對。
x = linspace(0, 2*pi, 100);
y = sin(x);
y2 = cos(x);
plot(x, y, '+1;sin(x);', "markersize", 10, x, y2, ";cos(x);", "markersize", 5, "marker", '*');
xlabel、ylabel、title 和 refresh
mesh、meshgrid、surf
contour
contour (Z)
contour (Z, VN)
contour (X, Y, Z)
contour (X, Y, Z, VN)
contour (..., STYLE)
contour (H, ...)
[C, H] = contour (...)
Plot level curves (contour lines) of the matrix Z, using the
contour matrix C computed by `contourc' from the same arguments;
see the latter for their interpretation. The set of contour
levels, C, is only returned if requested. For example:
x = 0:2;
y = x;
z = x' * y;
contour (x, y, z, 2:3)
The style to use for the plot can be defined with a line style
STYLE in a similar manner to the line styles used with the `plot'
command. Any markers defined by STYLE are ignored.
The optional input and output argument H allows an axis handle to
be passed to `contour' and the handles to the contour objects to be returned.
contourc
[C, LEV] = contourc (X, Y, Z, VN)
Compute isolines (contour lines) of the matrix Z. Parameters X, Y
and VN are optional.
The return value LEV is a vector of the contour levels. The
return value C is a 2 by N matrix containing the contour lines in
the following format
C = [lev1, x1, x2, ..., levn, x1, x2, ...
len1, y1, y2, ..., lenn, y1, y2, ...]
in which contour line N has a level (height) of LEVN and length of
LENN.
If X and Y are omitted they are taken as the row/column index of
Z. VN is either a scalar denoting the number of lines to compute
or a vector containing the values of the lines. If only one value
is wanted, set `VN = [val, val]'; If VN is omitted it defaults to
10.
For example,
x = 0:2;
y = x;
z = x' * y;
contourc (x, y, z, 2:3)
=> 2.0000 2.0000 1.0000 3.0000 1.5000 2.0000
2.0000 1.0000 2.0000 2.0000 2.0000 1.5000
colormap、image、imshow、hsv2rgb
>> help colormap 'colormap' is a function from the file C:\Octave\Octave-4.0.1\share\octave\4.0.1\ m\image\colormap.m
-- Function File: CMAP = colormap ()
-- Function File: CMAP = colormap (MAP)
-- Function File: CMAP = colormap ("default")
-- Function File: CMAP = colormap ("MAP_NAME")
-- Function File: CMAP = colormap (HAX, ...)
-- Command: colormap MAP_NAME
-- Function File: CMAPS = colormap ("list")
-- Function File: colormap ("register", "NAME")
-- Function File: colormap ("unregister", "NAME")
Query or set the current colormap.
With no input arguments, `colormap' returns the current color map.
`colormap (MAP)' sets the current colormap to MAP. The colormap
should be an N row by 3 column matrix. The columns contain red,
green, and blue intensities respectively. All entries must be
between 0 and 1 inclusive. The new colormap is returned.
`colormap ("default")' restores the default colormap (the `jet'
map with 64 entries). The default colormap is returned.
The map may also be specified by a string, "MAP_NAME", where
MAP_NAME is the name of a function that returns a colormap.
If the first argument HAX is an axes handle, then the colormap for
the parent figure of HAX is queried or set.
For convenience, it is also possible to use this function with the
command form, `colormap MAP_NAME'.
`colormap ("list")' returns a cell array with all of the available
colormaps. The options "register" and "unregister" add or remove
the colormap NAME from this list.
See also: jet.
將圖形列印到印表機或儲存到檔案
print("-Pprinter")
print("filename", "-ddevice")
裝置
`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
`svg`
Scalar Vector Graphics
如果省略裝置,則從副檔名推斷,或者如果沒有檔名,則以 Postscript 格式傳送到印表機。