annotate scripts/plot/quiver.m @ 8056:9a6f4713f765

Add area, bar, quiver and stair series graphics objects. Document them
author David Bateman <dbateman@free.fr>
date Tue, 26 Aug 2008 11:58:14 -0400
parents dd88d61d443f
children ec4d9d657b17
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7120
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 2007 David Bateman
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
2 ##
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
4 ##
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
8 ## your option) any later version.
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
9 ##
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
14 ##
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
18
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
20 ## @deftypefn {Function File} {} quiver (@var{u}, @var{v})
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
21 ## @deftypefnx {Function File} {} quiver (@var{x}, @var{y}, @var{u}, @var{v})
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
22 ## @deftypefnx {Function File} {} quiver (@dots{}, @var{s})
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
23 ## @deftypefnx {Function File} {} quiver (@dots{}, @var{style})
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
24 ## @deftypefnx {Function File} {} quiver (@dots{}, 'filled')
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
25 ## @deftypefnx {Function File} {} quiver (@var{h}, @dots{})
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
26 ## @deftypefnx {Function File} {@var{h} =} quiver (@dots{})
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
27 ##
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
28 ## Plot the @code{(@var{u}, @var{v})} components of a vector field in
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
29 ## an @code{(@var{x}, @var{y})} meshgrid. If the grid is uniform, you can
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
30 ## specify @var{x} and @var{y} as vectors.
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
31 ##
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
32 ## If @var{x} and @var{y} are undefined they are assumed to be
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
33 ## @code{(1:@var{m}, 1:@var{n})} where @code{[@var{m}, @var{n}] =
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
34 ## size(@var{u})}.
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
35 ##
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
36 ## The variable @var{s} is a scalar defining a scaling factor to use for
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
37 ## the arrows of the field relative to the mesh spacing. A value of 0
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
38 ## disables all scaling. The default value is 1.
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
39 ##
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
40 ## The style to use for the plot can be defined with a line style @var{style}
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
41 ## in a similar manner to the line styles used with the @code{plot} command.
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
42 ## If a marker is specified then markers at the grid points of the vectors are
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
43 ## printed rather than arrows. If the argument 'filled' is given then the
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
44 ## markers as filled.
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
45 ##
8056
9a6f4713f765 Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents: 7215
diff changeset
46 ## The optional return value @var{h} provides a quiver group that
9a6f4713f765 Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents: 7215
diff changeset
47 ## regroups the components of the quiver plot (body, arrow and marker),
9a6f4713f765 Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents: 7215
diff changeset
48 ## and allows them to be changed together
7120
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
49 ##
7121
c0d9ac299176 [project @ 2007-11-07 21:32:57 by jwe]
jwe
parents: 7120
diff changeset
50 ## @example
7120
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
51 ## @group
7121
c0d9ac299176 [project @ 2007-11-07 21:32:57 by jwe]
jwe
parents: 7120
diff changeset
52 ## [x, y] = meshgrid (1:2:20);
8056
9a6f4713f765 Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents: 7215
diff changeset
53 ## h = quiver (x, y, sin (2*pi*x/10), sin (2*pi*y/10));
9a6f4713f765 Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents: 7215
diff changeset
54 ## set (h, "maxheadsize", 0.33);
7121
c0d9ac299176 [project @ 2007-11-07 21:32:57 by jwe]
jwe
parents: 7120
diff changeset
55 ## @end group
7120
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
56 ## @end example
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
57 ##
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
58 ## @seealso{plot}
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
59 ## @end deftypefn
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
60
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
61 function retval = quiver (varargin)
7121
c0d9ac299176 [project @ 2007-11-07 21:32:57 by jwe]
jwe
parents: 7120
diff changeset
62
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
63 [h, varargin, nargin] = __plt_get_axis_arg__ ("quiver", varargin{:});
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
64
7120
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
65 if (nargin < 2)
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
66 print_usage ();
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
67 else
7120
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
68 oldh = gca ();
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
69 unwind_protect
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
70 axes (h);
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
71 newplot ();
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
72 tmp = __quiver__ (h, 0, varargin{:});
7120
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
73 unwind_protect_cleanup
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
74 axes (oldh);
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
75 end_unwind_protect
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
76 endif
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
77
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
78 if (nargout > 0)
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
79 retval = tmp;
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
80 endif
7121
c0d9ac299176 [project @ 2007-11-07 21:32:57 by jwe]
jwe
parents: 7120
diff changeset
81
7120
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
82 endfunction
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
83
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
84 %!demo
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
85 %! [x,y] = meshgrid(1:2:20);
8056
9a6f4713f765 Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents: 7215
diff changeset
86 %! h = quiver(x,y,sin(2*pi*x/10),sin(2*pi*y/10))
9a6f4713f765 Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents: 7215
diff changeset
87 %! set (h, "maxheadsize", 0.33);
7120
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
88
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
89 %!demo
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
90 %! axis("equal");
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
91 %! x=linspace(0,3,80); y=sin(2*pi*x); theta=2*pi*x+pi/2;
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
92 %! quiver(x,y,sin(theta)/10,cos(theta)/10);
a2174fb073d4 [project @ 2007-11-07 21:26:43 by jwe]
jwe
parents:
diff changeset
93 %! hold on; plot(x,y,"r"); hold off;