octave: Two-dimensional Function Plotting
15.2.1.2 Two-dimensional Function Plotting
..........................................
Octave can plot a function from a function handle, inline function, or
string defining the function without the user needing to explicitly
create the data to be plotted. The function ‘fplot’ also generates
two-dimensional plots with linear axes using a function name and limits
for the range of the x-coordinate instead of the x and y data. For
example,
fplot (@sin, [-10, 10], 201);
produces a plot that is equivalent to the one above, but also includes a
legend displaying the name of the plotted function.
-- : fplot (FN, LIMITS)
-- : fplot (..., TOL)
-- : fplot (..., N)
-- : fplot (..., FMT)
-- : [X, Y] = fplot (...)
Plot a function FN within the range defined by LIMITS.
FN is a function handle, inline function, or string containing the
name of the function to evaluate.
The limits of the plot are of the form ‘[XLO, XHI]’ or
‘[XLO, XHI, YLO, YHI]’.
The next three arguments are all optional and any number of them
may be given in any order.
TOL is the relative tolerance to use for the plot and defaults to
2e-3 (.2%).
N is the minimum number of points to use. When N is specified, the
maximum stepsize will be ‘(XHI - XLO) / N’. More than N points may
still be used in order to meet the relative tolerance requirement.
The FMT argument specifies the linestyle to be used by the plot
command.
If the first argument HAX is an axes handle, then plot into this
axes, rather than the current axes returned by ‘gca’.
With no output arguments the results are immediately plotted. With
two output arguments the 2-D plot data is returned. The data can
subsequently be plotted manually with ‘plot (X, Y)’.
Example:
fplot (@cos, [0, 2*pi])
fplot ("[cos(x), sin(x)]", [0, 2*pi])
Programming Notes:
‘fplot’ works best with continuous functions. Functions with
discontinuities are unlikely to plot well. This restriction may be
removed in the future.
‘fplot’ requires that the function accept and return a vector
argument. Consider this when writing user-defined functions and
use ‘.*’, ‘./’, etc. See the function ‘vectorize’ for potentially
converting inline or anonymous functions to vectorized versions.
DONTPRINTYET See also: ezplot XREFezplot, plot XREFplot, *noteDONTPRINTYET See also: ezplot XREFezplot, plot XREFplot,
vectorize XREFvectorize.
Other functions that can create two-dimensional plots directly from a
function include ‘ezplot’, ‘ezcontour’, ‘ezcontourf’ and ‘ezpolar’.
-- : ezplot (F)
-- : ezplot (F2V)
-- : ezplot (FX, FY)
-- : ezplot (..., DOM)
-- : ezplot (..., N)
-- : ezplot (HAX, ...)
-- : H = ezplot (...)
Plot the 2-D curve defined by the function F.
The function F may be a string, inline function, or function handle
and can have either one or two variables. If F has one variable,
then the function is plotted over the domain ‘-2*pi < X < 2*pi’
with 500 points.
If F2V is a function of two variables then the implicit function
‘F(X,Y) = 0’ is calculated over the meshed domain ‘-2*pi <= X | Y
<= 2*pi’ with 60 points in each dimension.
For example:
ezplot (@(X, Y) X.^2 - Y.^2 - 1)
If two functions are passed as inputs then the parametric function
X = FX (T)
Y = FY (T)
is plotted over the domain ‘-2*pi <= T <= 2*pi’ with 500 points.
If DOM is a two element vector, it represents the minimum and
maximum values of both X and Y, or T for a parametric plot. If DOM
is a four element vector, then the minimum and maximum values are
‘[xmin xmax ymin ymax]’.
N is a scalar defining the number of points to use in plotting the
function.
If the first argument HAX is an axes handle, then plot into this
axes, rather than the current axes returned by ‘gca’.
The optional return value H is a vector of graphics handles to the
created line objects.
DONTPRINTYET See also: plot XREFplot, ezplot3 XREFezplot3, *noteDONTPRINTYET DONTPRINTYET See also: plot XREFplot, ezplot3 XREFezplot3,
ezpolar XREFezpolar, ezcontour XREFezcontour, *noteDONTPRINTYET DONTPRINTYET DONTPRINTYET See also: plot XREFplot, ezplot3 XREFezplot3,
ezpolar XREFezpolar, ezcontour XREFezcontour,
ezcontourf XREFezcontourf, ezmesh XREFezmesh, *noteDONTPRINTYET DONTPRINTYET DONTPRINTYET DONTPRINTYET See also: plot XREFplot, ezplot3 XREFezplot3,
ezpolar XREFezpolar, ezcontour XREFezcontour,
ezcontourf XREFezcontourf, ezmesh XREFezmesh,
ezmeshc XREFezmeshc, ezsurf XREFezsurf, *noteezsurfc:
DONTPRINTYET DONTPRINTYET DONTPRINTYET DONTPRINTYET See also: plot XREFplot, ezplot3 XREFezplot3,
ezpolar XREFezpolar, ezcontour XREFezcontour,
ezcontourf XREFezcontourf, ezmesh XREFezmesh,
ezmeshc XREFezmeshc, ezsurf XREFezsurf, ezsurfc
XREFezsurfc.
-- : ezcontour (F)
-- : ezcontour (..., DOM)
-- : ezcontour (..., N)
-- : ezcontour (HAX, ...)
-- : H = ezcontour (...)
Plot the contour lines of a function.
F is a string, inline function, or function handle with two
arguments defining the function. By default the plot is over the
meshed domain ‘-2*pi <= X | Y <= 2*pi’ with 60 points in each
dimension.
If DOM is a two element vector, it represents the minimum and
maximum values of both X and Y. If DOM is a four element vector,
then the minimum and maximum values are ‘[xmin xmax ymin ymax]’.
N is a scalar defining the number of points to use in each
dimension.
If the first argument HAX is an axes handle, then plot into this
axes, rather than the current axes returned by ‘gca’.
The optional return value H is a graphics handle to the created
plot.
Example:
f = @(x,y) sqrt (abs (x .* y)) ./ (1 + x.^2 + y.^2);
ezcontour (f, [-3, 3]);
DONTPRINTYET See also: contour XREFcontour, *noteezcontourf:
DONTPRINTYET DONTPRINTYET See also: contour XREFcontour, ezcontourf
XREFezcontourf, ezplot XREFezplot, *noteezmeshc:
DONTPRINTYET DONTPRINTYET See also: contour XREFcontour, ezcontourf
XREFezcontourf, ezplot XREFezplot, ezmeshc
XREFezmeshc, ezsurfc XREFezsurfc.
-- : ezcontourf (F)
-- : ezcontourf (..., DOM)
-- : ezcontourf (..., N)
-- : ezcontourf (HAX, ...)
-- : H = ezcontourf (...)
Plot the filled contour lines of a function.
F is a string, inline function, or function handle with two
arguments defining the function. By default the plot is over the
meshed domain ‘-2*pi <= X | Y <= 2*pi’ with 60 points in each
dimension.
If DOM is a two element vector, it represents the minimum and
maximum values of both X and Y. If DOM is a four element vector,
then the minimum and maximum values are ‘[xmin xmax ymin ymax]’.
N is a scalar defining the number of points to use in each
dimension.
If the first argument HAX is an axes handle, then plot into this
axes, rather than the current axes returned by ‘gca’.
The optional return value H is a graphics handle to the created
plot.
Example:
f = @(x,y) sqrt (abs (x .* y)) ./ (1 + x.^2 + y.^2);
ezcontourf (f, [-3, 3]);
DONTPRINTYET See also: contourf XREFcontourf, *noteezcontour:
DONTPRINTYET DONTPRINTYET See also: contourf XREFcontourf, ezcontour
XREFezcontour, ezplot XREFezplot, *noteezmeshc:
DONTPRINTYET DONTPRINTYET See also: contourf XREFcontourf, ezcontour
XREFezcontour, ezplot XREFezplot, ezmeshc
XREFezmeshc, ezsurfc XREFezsurfc.
-- : ezpolar (F)
-- : ezpolar (..., DOM)
-- : ezpolar (..., N)
-- : ezpolar (HAX, ...)
-- : H = ezpolar (...)
Plot a 2-D function in polar coordinates.
The function F is a string, inline function, or function handle
with a single argument. The expected form of the function is ‘RHO
= F(THETA)’. By default the plot is over the domain ‘0 <= THETA <=
2*pi’ with 500 points.
If DOM is a two element vector, it represents the minimum and
maximum values of THETA.
N is a scalar defining the number of points to use in plotting the
function.
If the first argument HAX is an axes handle, then plot into this
axes, rather than the current axes returned by ‘gca’.
The optional return value H is a graphics handle to the created
plot.
Example:
ezpolar (@(t) sin (5/4 * t), [0, 8*pi]);
See also: polar XREFpolar, ezplot XREFezplot.