annotate scripts/plot/draw/rose.m @ 19630:0e1f5a750d00

maint: Periodic merge of gui-release to default.
author John W. Eaton <jwe@octave.org>
date Tue, 20 Jan 2015 10:24:46 -0500
parents 9a5e03801d23 446c46af4b42
children 4197fc428c7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
1 ## Copyright (C) 2007-2013 David Bateman
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
2 ##
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
4 ##
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
8 ## your option) any later version.
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
9 ##
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
14 ##
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
18
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
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
9a6012d7cbb7 Minor texinfo errors
David Bateman <dbateman@free.fr>
parents: 7322
diff changeset
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 ## Plot an angular histogram.
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
27 ##
17072
22fa8c77b92d polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16814
diff changeset
28 ## 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
29 ## 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
30 ## histogram.
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
31 ##
17072
22fa8c77b92d polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16814
diff changeset
32 ## 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
33 ## @var{nbin} bins. If @var{bins} is a vector, then the center of each bin is
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17072
diff changeset
34 ## defined by the values of @var{bins} and the number of bins is
17072
22fa8c77b92d polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16814
diff changeset
35 ## given by the number of elements in @var{bins}.
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
36 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17072
diff changeset
37 ## If the first argument @var{hax} is an axes handle, then plot into this axis,
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17072
diff changeset
38 ## rather than the current axes returned by @code{gca}.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17072
diff changeset
39 ##
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
40 ## 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
41 ## line objects representing each histogram.
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
42 ##
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
43 ## If two output arguments are requested then no plot is made and
16814
64e7bb01fce2 doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents: 14872
diff changeset
44 ## the polar vectors necessary to plot the histogram are returned instead.
7710
9a6012d7cbb7 Minor texinfo errors
David Bateman <dbateman@free.fr>
parents: 7322
diff changeset
45 ##
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
46 ## @example
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 9040
diff changeset
47 ## @group
17072
22fa8c77b92d polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16814
diff changeset
48 ## [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
49 ## polar (th, r);
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 9040
diff changeset
50 ## @end group
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
51 ## @end example
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
52 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17072
diff changeset
53 ## @seealso{hist, polar}
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
54 ## @end deftypefn
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
55
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
56 function [thout, rout] = rose (varargin)
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
57
17072
22fa8c77b92d polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16814
diff changeset
58 [hax, varargin, nargin] = __plt_get_axis_arg__ ("rose", varargin{:});
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
59
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
60 if (nargin < 1)
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
61 print_usage ();
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
62 endif
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
63
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
64 ## 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
65 th = varargin{1};
22fa8c77b92d polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16814
diff changeset
66 th = atan2 (sin (th), cos (th)) + pi;
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
67
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
68 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
69 x = varargin{2};
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
70 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
71 x = [0.5/x : 1/x : 1] * 2*pi;
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
72 else
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
73 ## 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
74 x = atan2 (sin (x), cos (x)) + pi;
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
75 endif
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
76 else
17072
22fa8c77b92d polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16814
diff changeset
77 x = [1/40 : 1/20 : 1] * 2*pi;
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
78 endif
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
79
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
80 [nn, xx] = hist (th, x);
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
81 xx = xx(:).';
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
82 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
83 nn = nn(:);
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
84 endif
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
85 x1 = xx(1:end-1) + diff (xx, 1) / 2;
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
86 x1 = [x1 ; x1; x1; x1](:);
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
87 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
88 r = zeros (4 * rows (nn), columns (nn));
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
89 r(2:4:end, :) = nn;
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
90 r(3:4:end, :) = nn;
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
91
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
92 if (nargout < 2)
17476
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
93 oldfig = [];
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
94 if (! isempty (hax))
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
95 oldfig = get (0, "currentfigure");
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
96 endif
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
97 unwind_protect
17072
22fa8c77b92d polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16814
diff changeset
98 hax = newplot (hax);
17126
26589abbc78d Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents: 17122
diff changeset
99 htmp = polar (th, r);
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
100 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
101 if (! isempty (oldfig))
22fa8c77b92d polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16814
diff changeset
102 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
103 endif
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
104 end_unwind_protect
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
105
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
106 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
107 thout = htmp;
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
108 endif
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
109 else
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
110 thout = th;
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
111 rout = r;
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
112 endif
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
113
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
114 endfunction
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
115
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
116
7322
40a17a87155e [project @ 2007-12-18 21:32:10 by jwe]
jwe
parents:
diff changeset
117 %!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
118 %! clf;
18958
9a5e03801d23 Update some plot %!demos so that they run under Matlab.
Rik <rik@octave.org>
parents: 17744
diff changeset
119 %! rose (2*randn (1e5, 1), 8);
9a5e03801d23 Update some plot %!demos so that they run under Matlab.
Rik <rik@octave.org>
parents: 17744
diff changeset
120 %! title ('rose() angular histogram plot with 8 bins');
9a5e03801d23 Update some plot %!demos so that they run under Matlab.
Rik <rik@octave.org>
parents: 17744
diff changeset
121
9a5e03801d23 Update some plot %!demos so that they run under Matlab.
Rik <rik@octave.org>
parents: 17744
diff changeset
122 %!demo
9a5e03801d23 Update some plot %!demos so that they run under Matlab.
Rik <rik@octave.org>
parents: 17744
diff changeset
123 %! clf;
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
124 %! rose ([2*randn(1e5, 1), pi + 2*randn(1e5, 1)]);
18958
9a5e03801d23 Update some plot %!demos so that they run under Matlab.
Rik <rik@octave.org>
parents: 17744
diff changeset
125 %! title ('rose() angular histogram plot with 2 data series');
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
126