Mercurial > hg > octave-lyh
annotate 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 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14092
diff
changeset
|
1 ## Copyright (C) 2007-2012 David Bateman |
7322 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
20 ## @deftypefn {Function File} {} rose (@var{th}) |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
21 ## @deftypefnx {Function File} {} rose (@var{th}, @var{nbins}) |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
22 ## @deftypefnx {Function File} {} rose (@var{th}, @var{bins}) |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
23 ## @deftypefnx {Function File} {} rose (@var{hax}, @dots{}) |
7710 | 24 ## @deftypefnx {Function File} {@var{h} =} rose (@dots{}) |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
25 ## @deftypefnx {Function File} {[@var{thout} @var{rout}] =} rose (@dots{}) |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
26 ## |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
27 ## Plot an angular histogram. |
7322 | 28 ## |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
29 ## With one vector argument, @var{th}, plot the histogram with 20 angular bins. |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
30 ## If @var{th} is a matrix then each column of @var{th} produces a separate |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
31 ## histogram. |
7322 | 32 ## |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
33 ## If @var{nbins} is given and is a scalar, then the histogram is produced with |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
34 ## @var{nbin} bins. If @var{bins} is a vector, then the center of each bin is |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
35 ## defined defined by the values of @var{bins} and the number of bins is |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
36 ## given by the number of elements in @var{bins}. |
7322 | 37 ## |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
38 ## The optional return value @var{h} is a vector of graphics handles to the |
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
39 ## line objects representing each histogram. |
7322 | 40 ## |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
41 ## If two output arguments are requested then no plot is made and |
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
42 ## the polar vectors necessary to plot the histogram are returned instead. |
7710 | 43 ## |
7322 | 44 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
45 ## @group |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
46 ## [th, r] = rose ([2*randn(1e5,1), pi + 2*randn(1e5,1)]); |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
47 ## polar (th, r); |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
48 ## @end group |
7322 | 49 ## @end example |
50 ## | |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
51 ## @seealso{polar, compass, hist} |
7322 | 52 ## @end deftypefn |
53 | |
54 function [thout, rout] = rose (varargin) | |
55 | |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
56 [hax, varargin, nargin] = __plt_get_axis_arg__ ("rose", varargin{:}); |
7322 | 57 |
58 if (nargin < 1) | |
59 print_usage (); | |
60 endif | |
61 | |
62 ## Force theta to [0,2*pi] range | |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
63 th = varargin{1}; |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
64 th = atan2 (sin (th), cos (th)) + pi; |
7322 | 65 |
66 if (nargin > 1) | |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
67 x = varargin{2}; |
7322 | 68 if (isscalar (x)) |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
69 x = [0.5/x : 1/x : 1] * 2*pi; |
7322 | 70 else |
71 ## Force theta to [0,2*pi] range | |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
72 x = atan2 (sin (x), cos (x)) + pi; |
7322 | 73 endif |
74 else | |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
75 x = [1/40 : 1/20 : 1] * 2*pi; |
7322 | 76 endif |
77 | |
78 [nn, xx] = hist (th, x); | |
79 xx = xx(:).'; | |
80 if (isvector (nn)) | |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
81 nn = nn(:); |
7322 | 82 endif |
83 x1 = xx(1:end-1) + diff (xx, 1) / 2; | |
84 x1 = [x1 ; x1; x1; x1](:); | |
85 th = [0; 0; x1; 2*pi ; 2*pi]; | |
14872
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
86 r = zeros (4 * rows (nn), columns (nn)); |
7322 | 87 r(2:4:end, :) = nn; |
88 r(3:4:end, :) = nn; | |
89 | |
90 if (nargout < 2) | |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
91 oldfig = ifelse (isempty (hax), [], get (0, "currentfigure")); |
7322 | 92 unwind_protect |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
93 hax = newplot (hax); |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
94 htmp = polar (hax, th, r); |
7322 | 95 unwind_protect_cleanup |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
96 if (! isempty (oldfig)) |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
97 set (0, "currentfigure", oldfig); |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
98 endif |
7322 | 99 end_unwind_protect |
100 | |
101 if (nargout > 0) | |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
102 thout = htmp; |
7322 | 103 endif |
104 else | |
105 thout = th; | |
106 rout = r; | |
107 endif | |
108 | |
109 endfunction | |
110 | |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
111 |
7322 | 112 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
113 %! clf; |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
114 %! rose ([2*randn(1e5, 1), pi + 2*randn(1e5, 1)]); |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
115 |