Mercurial > octave-nkf
comparison scripts/plot/rose.m @ 17072:22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
* scripts/plot/polar.m: Overhaul to use new __plt_get_axis_arg__.
Redo docstring. Simplify calculations to match sizes of rho and theta.
Use "polar" in all error() messages. Add %!demo showing complex input.
* scripts/plot/rose.m: Overhaul to use new __plt_get_axis_arg__.
Redo docstring.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 24 Jul 2013 23:12:46 -0700 |
parents | 64e7bb01fce2 |
children | eaab03308c0b |
comparison
equal
deleted
inserted
replaced
17071:e89fd58a6e84 | 17072:22fa8c77b92d |
---|---|
16 ## along with Octave; see the file COPYING. If not, see | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} rose (@var{th}) | 20 ## @deftypefn {Function File} {} rose (@var{th}) |
21 ## @deftypefnx {Function File} {} rose (@var{th}, @var{r}) | 21 ## @deftypefnx {Function File} {} rose (@var{th}, @var{nbins}) |
22 ## @deftypefnx {Function File} {} rose (@var{h}, @dots{}) | 22 ## @deftypefnx {Function File} {} rose (@var{th}, @var{bins}) |
23 ## @deftypefnx {Function File} {} rose (@var{hax}, @dots{}) | |
23 ## @deftypefnx {Function File} {@var{h} =} rose (@dots{}) | 24 ## @deftypefnx {Function File} {@var{h} =} rose (@dots{}) |
24 ## @deftypefnx {Function File} {[@var{r}, @var{th}] =} rose (@dots{}) | 25 ## @deftypefnx {Function File} {[@var{thout} @var{rout}] =} rose (@dots{}) |
25 ## | 26 ## |
26 ## Plot an angular histogram. With one vector argument, @var{th}, plot the | 27 ## Plot an angular histogram. |
27 ## histogram with 20 angular bins. If @var{th} is a matrix then each column | |
28 ## of @var{th} produces a separate histogram. | |
29 ## | 28 ## |
30 ## If @var{r} is given and is a scalar, then the histogram is produced with | 29 ## With one vector argument, @var{th}, plot the histogram with 20 angular bins. |
31 ## @var{r} bins. If @var{r} is a vector, then the center of each bin are | 30 ## If @var{th} is a matrix then each column of @var{th} produces a separate |
32 ## defined by the values of @var{r}. | 31 ## histogram. |
32 ## | |
33 ## If @var{nbins} is given and is a scalar, then the histogram is produced with | |
34 ## @var{nbin} bins. If @var{bins} is a vector, then the center of each bin is | |
35 ## defined defined by the values of @var{bins} and the number of bins is | |
36 ## given by the number of elements in @var{bins}. | |
33 ## | 37 ## |
34 ## The optional return value @var{h} is a vector of graphics handles to the | 38 ## The optional return value @var{h} is a vector of graphics handles to the |
35 ## line objects representing each histogram. | 39 ## line objects representing each histogram. |
36 ## | 40 ## |
37 ## If two output arguments are requested then no plot is made and | 41 ## If two output arguments are requested then no plot is made and |
38 ## the polar vectors necessary to plot the histogram are returned instead. | 42 ## the polar vectors necessary to plot the histogram are returned instead. |
39 ## | 43 ## |
40 ## @example | 44 ## @example |
41 ## @group | 45 ## @group |
42 ## [r, th] = rose ([2*randn(1e5,1), pi + 2*randn(1e5,1)]); | 46 ## [th, r] = rose ([2*randn(1e5,1), pi + 2*randn(1e5,1)]); |
43 ## polar (r, th); | 47 ## polar (th, r); |
44 ## @end group | 48 ## @end group |
45 ## @end example | 49 ## @end example |
46 ## | 50 ## |
47 ## @seealso{polar, compass, hist} | 51 ## @seealso{polar, compass, hist} |
48 ## @end deftypefn | 52 ## @end deftypefn |
49 | 53 |
50 function [thout, rout] = rose (varargin) | 54 function [thout, rout] = rose (varargin) |
51 | 55 |
52 [h, varargin, nargin] = __plt_get_axis_arg__ ((nargout > 1), "rose", | 56 [hax, varargin, nargin] = __plt_get_axis_arg__ ("rose", varargin{:}); |
53 varargin{:}); | |
54 | 57 |
55 if (nargin < 1) | 58 if (nargin < 1) |
56 print_usage (); | 59 print_usage (); |
57 endif | 60 endif |
58 | 61 |
59 ## Force theta to [0,2*pi] range | 62 ## Force theta to [0,2*pi] range |
60 th = varargin {1}; | 63 th = varargin{1}; |
61 th = atan2 (sin (th), cos (th)) + pi; | 64 th = atan2 (sin (th), cos (th)) + pi; |
62 | 65 |
63 if (nargin > 1) | 66 if (nargin > 1) |
64 x = varargin {2}; | 67 x = varargin{2}; |
65 if (isscalar (x)) | 68 if (isscalar (x)) |
66 x = [0.5/x : 1/x : 1] * 2 * pi; | 69 x = [0.5/x : 1/x : 1] * 2*pi; |
67 else | 70 else |
68 ## Force theta to [0,2*pi] range | 71 ## Force theta to [0,2*pi] range |
69 x = atan2 (sin (x), cos (x)) + pi; | 72 x = atan2 (sin (x), cos (x)) + pi; |
70 endif | 73 endif |
71 else | 74 else |
72 x = [1/40 : 1/20 : 1] * 2 * pi; | 75 x = [1/40 : 1/20 : 1] * 2*pi; |
73 endif | 76 endif |
74 | 77 |
75 [nn, xx] = hist (th, x); | 78 [nn, xx] = hist (th, x); |
76 xx = xx(:).'; | 79 xx = xx(:).'; |
77 if (isvector (nn)) | 80 if (isvector (nn)) |
78 nn = nn (:); | 81 nn = nn(:); |
79 endif | 82 endif |
80 x1 = xx(1:end-1) + diff (xx, 1) / 2; | 83 x1 = xx(1:end-1) + diff (xx, 1) / 2; |
81 x1 = [x1 ; x1; x1; x1](:); | 84 x1 = [x1 ; x1; x1; x1](:); |
82 th = [0; 0; x1; 2*pi ; 2*pi]; | 85 th = [0; 0; x1; 2*pi ; 2*pi]; |
83 r = zeros (4 * rows (nn), columns (nn)); | 86 r = zeros (4 * rows (nn), columns (nn)); |
84 r(2:4:end, :) = nn; | 87 r(2:4:end, :) = nn; |
85 r(3:4:end, :) = nn; | 88 r(3:4:end, :) = nn; |
86 | 89 |
87 if (nargout < 2) | 90 if (nargout < 2) |
88 oldh = gca (); | 91 oldfig = ifelse (isempty (hax), [], get (0, "currentfigure")); |
89 unwind_protect | 92 unwind_protect |
90 axes (h); | 93 hax = newplot (hax); |
91 newplot (); | 94 htmp = polar (hax, th, r); |
92 hlist = polar (h, th, r); | |
93 unwind_protect_cleanup | 95 unwind_protect_cleanup |
94 axes (oldh); | 96 if (! isempty (oldfig)) |
97 set (0, "currentfigure", oldfig); | |
98 endif | |
95 end_unwind_protect | 99 end_unwind_protect |
96 | 100 |
97 if (nargout > 0) | 101 if (nargout > 0) |
98 thout = hlist; | 102 thout = htmp; |
99 endif | 103 endif |
100 else | 104 else |
101 thout = th; | 105 thout = th; |
102 rout = r; | 106 rout = r; |
103 endif | 107 endif |