1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Two-dimensional Function Plotting (GNU Octave (version 6.2.0))</title>
<meta name="description" content="Two-dimensional Function Plotting (GNU Octave (version 6.2.0))">
<meta name="keywords" content="Two-dimensional Function Plotting (GNU Octave (version 6.2.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Two_002dDimensional-Plots.html" rel="up" title="Two-Dimensional Plots">
<link href="Two_002ddimensional-Geometric-Shapes.html" rel="next" title="Two-dimensional Geometric Shapes">
<link href="Axis-Configuration.html" rel="prev" title="Axis Configuration">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<span id="Two_002ddimensional-Function-Plotting"></span><div class="header">
<p>
Next: <a href="Two_002ddimensional-Geometric-Shapes.html" accesskey="n" rel="next">Two-dimensional Geometric Shapes</a>, Previous: <a href="Axis-Configuration.html" accesskey="p" rel="prev">Axis Configuration</a>, Up: <a href="Two_002dDimensional-Plots.html" accesskey="u" rel="up">Two-Dimensional Plots</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Two_002ddimensional-Function-Plotting-1"></span><h4 class="subsubsection">15.2.1.2 Two-dimensional Function Plotting</h4>
<span id="index-plotting_002c-two_002ddimensional-functions"></span>
<p>Octave can plot a function from a function handle or string defining the
function without the user needing to explicitly create the data to be
plotted. The function <code>fplot</code> 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,
</p>
<div class="example">
<pre class="example">fplot (@sin, [-10, 10], 201);
</pre></div>
<p>produces a plot that is equivalent to the one above, but also includes a
legend displaying the name of the plotted function.
</p>
<span id="XREFfplot"></span><dl>
<dt id="index-fplot">: <em></em> <strong>fplot</strong> <em>(<var>fn</var>)</em></dt>
<dt id="index-fplot-1">: <em></em> <strong>fplot</strong> <em>(<var>fn</var>, <var>limits</var>)</em></dt>
<dt id="index-fplot-2">: <em></em> <strong>fplot</strong> <em>(…, <var>tol</var>)</em></dt>
<dt id="index-fplot-3">: <em></em> <strong>fplot</strong> <em>(…, <var>n</var>)</em></dt>
<dt id="index-fplot-4">: <em></em> <strong>fplot</strong> <em>(…, <var>fmt</var>)</em></dt>
<dt id="index-fplot-5">: <em></em> <strong>fplot</strong> <em>(…, <var>property</var>, <var>value</var>, …)</em></dt>
<dt id="index-fplot-6">: <em></em> <strong>fplot</strong> <em>(<var>hax</var>, …)</em></dt>
<dt id="index-fplot-7">: <em>[<var>x</var>, <var>y</var>] =</em> <strong>fplot</strong> <em>(…)</em></dt>
<dd><p>Plot a function <var>fn</var> within the range defined by <var>limits</var>.
</p>
<p><var>fn</var> is a function handle, inline function, or string containing the
name of the function to evaluate.
</p>
<p>The limits of the plot are of the form <code>[<var>xlo</var>, <var>xhi</var>]</code><!-- /@w --> or
<code>[<var>xlo</var>, <var>xhi</var>, <var>ylo</var>, <var>yhi</var>]</code><!-- /@w -->. If no limits
are specified the default is <code>[-5, 5]</code>.
</p>
<p>The next three arguments are all optional and any number of them may be
given in any order.
</p>
<p><var>tol</var> is the relative tolerance to use for the plot and defaults
to 2e-3 (.2%).
</p>
<p><var>n</var> is the minimum number of points to use. When <var>n</var> is specified,
the maximum stepsize will be <code>(<var>xhi</var> - <var>xlo</var>) / <var>n</var></code>. More
than <var>n</var> points may still be used in order to meet the relative
tolerance requirement.
</p>
<p>The <var>fmt</var> argument specifies the linestyle to be used by the plot
command.
</p>
<p>Multiple property-value pairs may also be specified, but they must appear
in pairs. These arguments are applied to the line objects drawn by
<code>plot</code>.
</p>
<p>The full list of line properties is documented at
<a href="Line-Properties.html">Line Properties</a>.
</p>
<p>If the first argument <var>hax</var> is an axes handle, then plot into this axes,
rather than the current axes returned by <code>gca</code>.
</p>
<p>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 <code>plot (<var>x</var>, <var>y</var>)</code>.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">fplot (@cos, [0, 2*pi])
fplot ("[cos(x), sin(x)]", [0, 2*pi])
</pre></div>
<p>Programming Notes:
</p>
<p><code>fplot</code> works best with continuous functions. Functions with
discontinuities are unlikely to plot well. This restriction may be removed
in the future.
</p>
<p><code>fplot</code> performance is better when the function accepts and returns a
vector argument. Consider this when writing user-defined functions and use
element-by-element operators such as <code>.*</code>, <code>./</code>, etc.
</p>
<p><strong>See also:</strong> <a href="#XREFezplot">ezplot</a>, <a href="Two_002dDimensional-Plots.html#XREFplot">plot</a>.
</p></dd></dl>
<p>Other functions that can create two-dimensional plots directly from a
function include <code>ezplot</code>, <code>ezcontour</code>, <code>ezcontourf</code> and
<code>ezpolar</code>.
</p>
<span id="XREFezplot"></span><dl>
<dt id="index-ezplot">: <em></em> <strong>ezplot</strong> <em>(<var>f</var>)</em></dt>
<dt id="index-ezplot-1">: <em></em> <strong>ezplot</strong> <em>(<var>f2v</var>)</em></dt>
<dt id="index-ezplot-2">: <em></em> <strong>ezplot</strong> <em>(<var>fx</var>, <var>fy</var>)</em></dt>
<dt id="index-ezplot-3">: <em></em> <strong>ezplot</strong> <em>(…, <var>dom</var>)</em></dt>
<dt id="index-ezplot-4">: <em></em> <strong>ezplot</strong> <em>(…, <var>n</var>)</em></dt>
<dt id="index-ezplot-5">: <em></em> <strong>ezplot</strong> <em>(<var>hax</var>, …)</em></dt>
<dt id="index-ezplot-6">: <em><var>h</var> =</em> <strong>ezplot</strong> <em>(…)</em></dt>
<dd>
<p>Plot the 2-D curve defined by the function <var>f</var>.
</p>
<p>The function <var>f</var> may be a string, inline function, or function handle
and can have either one or two variables. If <var>f</var> has one variable, then
the function is plotted over the domain <code>-2*pi < <var>x</var> < 2*pi</code>
with 500 points.
</p>
<p>If <var>f2v</var> is a function of two variables then the implicit function
<code><var>f</var>(<var>x</var>,<var>y</var>) = 0</code> is calculated over the meshed domain
<code>-2*pi <= <var>x</var> | <var>y</var> <= 2*pi</code> with 60 points in each dimension.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">ezplot (@(<var>x</var>, <var>y</var>) <var>x</var>.^2 - <var>y</var>.^2 - 1)
</pre></div>
<p>If two functions are passed as inputs then the parametric function
</p>
<div class="example">
<pre class="example"><var>x</var> = <var>fx</var> (<var>t</var>)
<var>y</var> = <var>fy</var> (<var>t</var>)
</pre></div>
<p>is plotted over the domain <code>-2*pi <= <var>t</var> <= 2*pi</code> with 500 points.
</p>
<p>If <var>dom</var> is a two element vector, it represents the minimum and maximum
values of both <var>x</var> and <var>y</var>, or <var>t</var> for a parametric plot. If
<var>dom</var> is a four element vector, then the minimum and maximum values are
<code>[xmin xmax ymin ymax]</code>.
</p>
<p><var>n</var> is a scalar defining the number of points to use in plotting
the function.
</p>
<p>If the first argument <var>hax</var> is an axes handle, then plot into this axes,
rather than the current axes returned by <code>gca</code>.
</p>
<p>The optional return value <var>h</var> is a vector of graphics handles to
the created line objects.
</p>
<p><strong>See also:</strong> <a href="Two_002dDimensional-Plots.html#XREFplot">plot</a>, <a href="Three_002ddimensional-Function-Plotting.html#XREFezplot3">ezplot3</a>, <a href="#XREFezpolar">ezpolar</a>, <a href="#XREFezcontour">ezcontour</a>, <a href="#XREFezcontourf">ezcontourf</a>, <a href="Three_002ddimensional-Function-Plotting.html#XREFezmesh">ezmesh</a>, <a href="Three_002ddimensional-Function-Plotting.html#XREFezmeshc">ezmeshc</a>, <a href="Three_002ddimensional-Function-Plotting.html#XREFezsurf">ezsurf</a>, <a href="Three_002ddimensional-Function-Plotting.html#XREFezsurfc">ezsurfc</a>.
</p></dd></dl>
<span id="XREFezcontour"></span><dl>
<dt id="index-ezcontour">: <em></em> <strong>ezcontour</strong> <em>(<var>f</var>)</em></dt>
<dt id="index-ezcontour-1">: <em></em> <strong>ezcontour</strong> <em>(…, <var>dom</var>)</em></dt>
<dt id="index-ezcontour-2">: <em></em> <strong>ezcontour</strong> <em>(…, <var>n</var>)</em></dt>
<dt id="index-ezcontour-3">: <em></em> <strong>ezcontour</strong> <em>(<var>hax</var>, …)</em></dt>
<dt id="index-ezcontour-4">: <em><var>h</var> =</em> <strong>ezcontour</strong> <em>(…)</em></dt>
<dd>
<p>Plot the contour lines of a function.
</p>
<p><var>f</var> is a string, inline function, or function handle with two arguments
defining the function. By default the plot is over the meshed domain
<code>-2*pi <= <var>x</var> | <var>y</var> <= 2*pi</code> with 60 points in each dimension.
</p>
<p>If <var>dom</var> is a two element vector, it represents the minimum and maximum
values of both <var>x</var> and <var>y</var>. If <var>dom</var> is a four element vector,
then the minimum and maximum values are <code>[xmin xmax ymin ymax]</code>.
</p>
<p><var>n</var> is a scalar defining the number of points to use in each dimension.
</p>
<p>If the first argument <var>hax</var> is an axes handle, then plot into this axes,
rather than the current axes returned by <code>gca</code>.
</p>
<p>The optional return value <var>h</var> is a graphics handle to the created plot.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">f = @(x,y) sqrt (abs (x .* y)) ./ (1 + x.^2 + y.^2);
ezcontour (f, [-3, 3]);
</pre></div>
<p><strong>See also:</strong> <a href="Two_002dDimensional-Plots.html#XREFcontour">contour</a>, <a href="#XREFezcontourf">ezcontourf</a>, <a href="#XREFezplot">ezplot</a>, <a href="Three_002ddimensional-Function-Plotting.html#XREFezmeshc">ezmeshc</a>, <a href="Three_002ddimensional-Function-Plotting.html#XREFezsurfc">ezsurfc</a>.
</p></dd></dl>
<span id="XREFezcontourf"></span><dl>
<dt id="index-ezcontourf">: <em></em> <strong>ezcontourf</strong> <em>(<var>f</var>)</em></dt>
<dt id="index-ezcontourf-1">: <em></em> <strong>ezcontourf</strong> <em>(…, <var>dom</var>)</em></dt>
<dt id="index-ezcontourf-2">: <em></em> <strong>ezcontourf</strong> <em>(…, <var>n</var>)</em></dt>
<dt id="index-ezcontourf-3">: <em></em> <strong>ezcontourf</strong> <em>(<var>hax</var>, …)</em></dt>
<dt id="index-ezcontourf-4">: <em><var>h</var> =</em> <strong>ezcontourf</strong> <em>(…)</em></dt>
<dd>
<p>Plot the filled contour lines of a function.
</p>
<p><var>f</var> is a string, inline function, or function handle with two arguments
defining the function. By default the plot is over the meshed domain
<code>-2*pi <= <var>x</var> | <var>y</var> <= 2*pi</code> with 60 points in each dimension.
</p>
<p>If <var>dom</var> is a two element vector, it represents the minimum and maximum
values of both <var>x</var> and <var>y</var>. If <var>dom</var> is a four element vector,
then the minimum and maximum values are <code>[xmin xmax ymin ymax]</code>.
</p>
<p><var>n</var> is a scalar defining the number of points to use in each dimension.
</p>
<p>If the first argument <var>hax</var> is an axes handle, then plot into this axes,
rather than the current axes returned by <code>gca</code>.
</p>
<p>The optional return value <var>h</var> is a graphics handle to the created plot.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">f = @(x,y) sqrt (abs (x .* y)) ./ (1 + x.^2 + y.^2);
ezcontourf (f, [-3, 3]);
</pre></div>
<p><strong>See also:</strong> <a href="Two_002dDimensional-Plots.html#XREFcontourf">contourf</a>, <a href="#XREFezcontour">ezcontour</a>, <a href="#XREFezplot">ezplot</a>, <a href="Three_002ddimensional-Function-Plotting.html#XREFezmeshc">ezmeshc</a>, <a href="Three_002ddimensional-Function-Plotting.html#XREFezsurfc">ezsurfc</a>.
</p></dd></dl>
<span id="XREFezpolar"></span><dl>
<dt id="index-ezpolar">: <em></em> <strong>ezpolar</strong> <em>(<var>f</var>)</em></dt>
<dt id="index-ezpolar-1">: <em></em> <strong>ezpolar</strong> <em>(…, <var>dom</var>)</em></dt>
<dt id="index-ezpolar-2">: <em></em> <strong>ezpolar</strong> <em>(…, <var>n</var>)</em></dt>
<dt id="index-ezpolar-3">: <em></em> <strong>ezpolar</strong> <em>(<var>hax</var>, …)</em></dt>
<dt id="index-ezpolar-4">: <em><var>h</var> =</em> <strong>ezpolar</strong> <em>(…)</em></dt>
<dd>
<p>Plot a 2-D function in polar coordinates.
</p>
<p>The function <var>f</var> is a string, inline function, or function handle with
a single argument. The expected form of the function is
<code><var>rho</var> = <var>f</var>(<var>theta</var>)</code>.
By default the plot is over the domain <code>0 <= <var>theta</var> <= 2*pi</code>
with 500 points.
</p>
<p>If <var>dom</var> is a two element vector, it represents the minimum and maximum
values of <var>theta</var>.
</p>
<p><var>n</var> is a scalar defining the number of points to use in plotting
the function.
</p>
<p>If the first argument <var>hax</var> is an axes handle, then plot into this axes,
rather than the current axes returned by <code>gca</code>.
</p>
<p>The optional return value <var>h</var> is a graphics handle to the created plot.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">ezpolar (@(t) sin (5/4 * t), [0, 8*pi]);
</pre></div>
<p><strong>See also:</strong> <a href="Two_002dDimensional-Plots.html#XREFpolar">polar</a>, <a href="#XREFezplot">ezplot</a>.
</p></dd></dl>
<hr>
<div class="header">
<p>
Next: <a href="Two_002ddimensional-Geometric-Shapes.html" accesskey="n" rel="next">Two-dimensional Geometric Shapes</a>, Previous: <a href="Axis-Configuration.html" accesskey="p" rel="prev">Axis Configuration</a>, Up: <a href="Two_002dDimensional-Plots.html" accesskey="u" rel="up">Two-Dimensional Plots</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|