Mercurial > hg > octave-nkf
annotate scripts/plot/rose.m @ 17190:df4c4b7708a4
Add titles and clean-up plotting %!demos.
* scripts/plot/area.m, scripts/plot/axis.m, scripts/plot/bar.m,
scripts/plot/barh.m, scripts/plot/clabel.m, scripts/plot/colorbar.m,
scripts/plot/comet.m, scripts/plot/comet3.m, scripts/plot/contour.m,
scripts/plot/contour3.m, scripts/plot/contourf.m, scripts/plot/cylinder.m,
scripts/plot/ellipsoid.m, scripts/plot/errorbar.m, scripts/plot/ezplot.m,
scripts/plot/ezplot3.m, scripts/plot/ezpolar.m, scripts/plot/feather.m,
scripts/plot/fplot.m, scripts/plot/hold.m, scripts/plot/isosurface.m,
scripts/plot/legend.m, scripts/plot/loglog.m, scripts/plot/loglogerr.m,
scripts/plot/mesh.m, scripts/plot/meshc.m, scripts/plot/meshz.m,
scripts/plot/patch.m, scripts/plot/pcolor.m, scripts/plot/pie.m,
scripts/plot/pie3.m, scripts/plot/plot.m, scripts/plot/plot3.m,
scripts/plot/polar.m, scripts/plot/rectangle.m, scripts/plot/ribbon.m,
scripts/plot/rose.m, scripts/plot/scatter.m, scripts/plot/scatter3.m,
scripts/plot/semilogx.m, scripts/plot/semilogxerr.m, scripts/plot/semilogy.m,
scripts/plot/semilogyerr.m, scripts/plot/sombrero.m, scripts/plot/stem3.m,
scripts/plot/surf.m, scripts/plot/surfc.m, scripts/plot/surfl.m,
scripts/plot/title.m, scripts/plot/waterfall.m: Add titles and clean-up
plotting %!demos.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 06 Aug 2013 14:34:20 -0700 |
parents | 26589abbc78d |
children | 87ba70043bfc |
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 |
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 | 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 | 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 ## | |
17122
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) | |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
93 oldfig = ifelse (isempty (hax), [], get (0, "currentfigure")); |
7322 | 94 unwind_protect |
17072
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
95 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
|
96 htmp = polar (th, r); |
7322 | 97 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
|
98 if (! isempty (oldfig)) |
22fa8c77b92d
polar.m, rose.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
99 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
|
100 endif |
7322 | 101 end_unwind_protect |
102 | |
103 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
|
104 thout = htmp; |
7322 | 105 endif |
106 else | |
107 thout = th; | |
108 rout = r; | |
109 endif | |
110 | |
111 endfunction | |
112 | |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
113 |
7322 | 114 %!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
|
115 %! clf; |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
116 %! rose ([2*randn(1e5, 1), pi + 2*randn(1e5, 1)]); |
17190
df4c4b7708a4
Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
117 %! 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
|
118 |