comparison scripts/plot/compass.m @ 17063:f17d9a574645

compass.m: Overhaul to use new __plt_get_axis_arg__. * scripts/plot/compass.m: Update to use new __plt_get_axis_arg__. Redo docstring.
author Rik <rik@octave.org>
date Wed, 24 Jul 2013 23:12:46 -0700
parents ce2b59a6d0e5
children eaab03308c0b
comparison
equal deleted inserted replaced
17062:19c3b5bf5c8e 17063:f17d9a574645
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} compass (@var{u}, @var{v}) 20 ## @deftypefn {Function File} {} compass (@var{u}, @var{v})
21 ## @deftypefnx {Function File} {} compass (@var{z}) 21 ## @deftypefnx {Function File} {} compass (@var{z})
22 ## @deftypefnx {Function File} {} compass (@dots{}, @var{style}) 22 ## @deftypefnx {Function File} {} compass (@dots{}, @var{style})
23 ## @deftypefnx {Function File} {} compass (@var{h}, @dots{}) 23 ## @deftypefnx {Function File} {} compass (@var{hax}, @dots{})
24 ## @deftypefnx {Function File} {@var{h} =} compass (@dots{}) 24 ## @deftypefnx {Function File} {@var{h} =} compass (@dots{})
25 ## 25 ##
26 ## Plot the @code{(@var{u}, @var{v})} components of a vector field emanating 26 ## Plot the @code{(@var{u}, @var{v})} components of a vector field emanating
27 ## from the origin of a polar plot. If a single complex argument @var{z} is 27 ## from the origin of a polar plot. If a single complex argument @var{z} is
28 ## given, then @code{@var{u} = real (@var{z})} and @code{@var{v} = imag 28 ## given, then @code{@var{u} = real (@var{z})} and @code{@var{v} = imag
29 ## (@var{z})}. 29 ## (@var{z})}.
30 ## 30 ##
31 ## The style to use for the plot can be defined with a line style @var{style} 31 ## The style to use for the plot can be defined with a line style @var{style}
32 ## in a similar manner to the line styles used with the @code{plot} command. 32 ## in a similar manner to the line styles used with the @code{plot} command.
33 ##
34 ## If the first argument @var{hax} is an axis handle, then plot into these axes,
35 ## rather than the current axis handle returned by @code{gca}.
33 ## 36 ##
34 ## The optional return value @var{h} is a vector of graphics handles to the 37 ## The optional return value @var{h} is a vector of graphics handles to the
35 ## line objects representing the drawn vectors. 38 ## line objects representing the drawn vectors.
36 ## 39 ##
37 ## @example 40 ## @example
42 ## @end example 45 ## @end example
43 ## 46 ##
44 ## @seealso{polar, quiver, feather, plot} 47 ## @seealso{polar, quiver, feather, plot}
45 ## @end deftypefn 48 ## @end deftypefn
46 49
47 function retval = compass (varargin) 50 function h = compass (varargin)
48 51
49 [h, varargin, nargin] = __plt_get_axis_arg__ ("compass", varargin{:}); 52 [hax, varargin, nargin] = __plt_get_axis_arg__ ("compass", varargin{:});
50
51 arrowsize = 0.25;
52 53
53 if (nargin == 0) 54 if (nargin == 0)
54 print_usage (); 55 print_usage ();
55 elseif (nargin == 1 || (nargin == 2 && ! isnumeric (varargin{2}))) 56 elseif (nargin == 1 || (nargin == 2 && ! isnumeric (varargin{2})))
56 ioff = 2; 57 ioff = 2;
61 ioff = 3; 62 ioff = 3;
62 u = varargin{1}(:).'; 63 u = varargin{1}(:).';
63 v = varargin{2}(:).'; 64 v = varargin{2}(:).';
64 endif 65 endif
65 66
67 arrowsize = 0.25;
66 line_spec = "b-"; 68 line_spec = "b-";
67 have_line_spec = false; 69 have_line_spec = false;
68 while (ioff <= nargin) 70 while (ioff <= nargin)
69 arg = varargin{ioff++}; 71 arg = varargin{ioff++};
70 if ((ischar (arg) || iscell (arg)) && ! have_line_spec) 72 if ((ischar (arg) || iscell (arg)) && ! have_line_spec)
93 xtmp + v * arrowsize / 3]; 95 xtmp + v * arrowsize / 3];
94 y = [zeros(1, n); yend; ytmp + u * arrowsize / 3; yend; ... 96 y = [zeros(1, n); yend; ytmp + u * arrowsize / 3; yend; ...
95 ytmp - u * arrowsize / 3]; 97 ytmp - u * arrowsize / 3];
96 [r, p] = cart2pol (x, y); 98 [r, p] = cart2pol (x, y);
97 99
98 oldh = gca (); 100 oldfig = ifelse (isempty (hax), [], get (0, "currentfigure"));
99 unwind_protect 101 unwind_protect
100 axes (h); 102 hax = newplot (hax);
101 newplot (); 103 hlist = polar (hax, r, p, line_spec);
102 hlist = polar (h, r, p, line_spec);
103 unwind_protect_cleanup 104 unwind_protect_cleanup
104 axes (oldh); 105 if (! isempty (oldfig))
106 set (0, "currentfigure", oldfig);
107 endif
105 end_unwind_protect 108 end_unwind_protect
106 109
107 if (nargout > 0) 110 if (nargout > 0)
108 retval = hlist; 111 h = hlist;
109 endif 112 endif
110 113
111 endfunction 114 endfunction
112 115
113 116