Mercurial > hg > octave-lyh
annotate scripts/plot/rose.m @ 17487:f0f4b524b6d0
maint: Correct indentation for several plot routines.
* scripts/plot/ellipsoid.m, scripts/plot/rose.m, scripts/plot/sphere.m,
scripts/plot/surfnorm.m: maint: Correct indentation for several plot routines.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 25 Sep 2013 07:48:58 -0700 |
parents | 68bcac3c043a |
children |
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 ## Plot an angular histogram. |
7322 | 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 | 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 |
17126
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 | 36 ## |
17126
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 | 42 ## |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
43 ## 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
|
44 ## the polar vectors necessary to plot the histogram are returned instead. |
7710 | 45 ## |
7322 | 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 | 51 ## @end example |
52 ## | |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17072
diff
changeset
|
53 ## @seealso{hist, polar} |
7322 | 54 ## @end deftypefn |
55 | |
56 function [thout, rout] = rose (varargin) | |
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 | 59 |
60 if (nargin < 1) | |
61 print_usage (); | |
62 endif | |
63 | |
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 | 67 |
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 | 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 | 72 else |
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 | 75 endif |
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 | 78 endif |
79 | |
80 [nn, xx] = hist (th, x); | |
81 xx = xx(:).'; | |
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 | 84 endif |
85 x1 = xx(1:end-1) + diff (xx, 1) / 2; | |
86 x1 = [x1 ; x1; x1; x1](:); | |
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 | 89 r(2:4:end, :) = nn; |
90 r(3:4:end, :) = nn; | |
91 | |
92 if (nargout < 2) | |
17487
f0f4b524b6d0
maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents:
17309
diff
changeset
|
93 oldfig = []; |
f0f4b524b6d0
maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents:
17309
diff
changeset
|
94 if (! isempty (hax)) |
f0f4b524b6d0
maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents:
17309
diff
changeset
|
95 oldfig = get (0, "currentfigure"); |
f0f4b524b6d0
maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents:
17309
diff
changeset
|
96 endif |
7322 | 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); |
17130
26589abbc78d
Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
99 htmp = polar (th, r); |
7322 | 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 | 104 end_unwind_protect |
105 | |
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 | 108 endif |
109 else | |
110 thout = th; | |
111 rout = r; | |
112 endif | |
113 | |
114 endfunction | |
115 | |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
116 |
7322 | 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; |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
119 %! rose ([2*randn(1e5, 1), pi + 2*randn(1e5, 1)]); |
17198
df4c4b7708a4
Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents:
17130
diff
changeset
|
120 %! title ('rose() angular histogram plot'); |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
121 |