annotate scripts/plot/scatter3.m @ 17396:e04847bbcfdf

Squeeze Nd > 2 plot vectors. * scripts/plot/__plt__.m: Squeeze input plot vectors when ndims>2. Throw error if there are more than 2 non-singleton dimensions. * scripts/plot/plot.m: Modify doc-string. Add demos.
author Ben Abbott <bpabbott@mac.com>
date Sat, 07 Sep 2013 12:21:38 -0400
parents 68bcac3c043a
children 5e552cd9315a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
2 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
3 ## This file is part of Octave.
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
4 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
8 ## your option) any later version.
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
9 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
13 ## General Public License for more details.
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
14 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
18
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
19 ## -*- texinfo -*-
17126
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
20 ## @deftypefn {Function File} {} scatter3 (@var{x}, @var{y}, @var{z})
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
21 ## @deftypefnx {Function File} {} scatter3 (@var{x}, @var{y}, @var{z}, @var{s})
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
22 ## @deftypefnx {Function File} {} scatter3 (@var{x}, @var{y}, @var{z}, @var{s}, @var{c})
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
23 ## @deftypefnx {Function File} {} scatter3 (@dots{}, @var{style})
17126
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
24 ## @deftypefnx {Function File} {} scatter3 (@dots{}, "filled")
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
25 ## @deftypefnx {Function File} {} scatter3 (@dots{}, @var{prop}, @var{val})
17126
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
26 ## @deftypefnx {Function File} {} scatter3 (@var{hax}, @dots{})
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
27 ## @deftypefnx {Function File} {@var{h} =} scatter3 (@dots{})
17126
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
28 ## Draw a 3-D scatter plot.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
29 ##
17126
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
30 ## A marker is plotted at each point defined by the coordinates in the vectors
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
31 ## @var{x}, @var{y}, and @var{z}.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
32 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
33 ## The size of the markers is determined by @var{s}, which can be a scalar
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
34 ## or a vector of the same length as @var{x}, @var{y}, and @var{z}. If @var{s}
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
35 ## is not given, or is an empty matrix, then a default value of 8 points is
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
36 ## used.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
37 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
38 ## The color of the markers is determined by @var{c}, which can be a string
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
39 ## defining a fixed color; a 3-element vector giving the red, green, and blue
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
40 ## components of the color; a vector of the same length as @var{x} that gives
17126
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
41 ## a scaled index into the current colormap; or an @nospell{Nx3} matrix defining
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
42 ## the RGB color of each marker individually.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
43 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
44 ## The marker to use can be changed with the @var{style} argument, that is a
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
45 ## string defining a marker in the same manner as the @code{plot} command.
17289
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17219
diff changeset
46 ## If no marker is specified it defaults to @qcode{"o"} or circles.
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17219
diff changeset
47 ## If the argument @qcode{"filled"} is given then the markers are filled.
17126
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
48 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
49 ## Additional property/value pairs are passed directly to the underlying
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
50 ## patch object.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
51 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
52 ## 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: 17069
diff changeset
53 ## rather than the current axes returned by @code{gca}.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
54 ##
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 12320
diff changeset
55 ## The optional return value @var{h} is a graphics handle to the hggroup
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 12320
diff changeset
56 ## object representing the points.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
57 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
58 ## @example
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
59 ## @group
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
60 ## [x, y, z] = peaks (20);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
61 ## scatter3 (x(:), y(:), z(:), [], z(:));
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
62 ## @end group
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
63 ## @end example
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
64 ##
17126
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17069
diff changeset
65 ## @seealso{scatter, patch, plot}
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
66 ## @end deftypefn
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
67
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
68 function retval = scatter3 (varargin)
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
69
17069
1cbdd14711c5 scatter3.m, scatter.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14359
diff changeset
70 [hax, varargin, nargin] = __plt_get_axis_arg__ ("scatter3", varargin{:});
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
71
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
72 if (nargin < 2)
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
73 print_usage ();
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
74 else
17219
87ba70043bfc Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents: 17198
diff changeset
75 oldfig = [];
17309
68bcac3c043a Correct inversion accidentally introduced in cset 87ba70043bfc.
Rik <rik@octave.org>
parents: 17289
diff changeset
76 if (! isempty (hax))
17219
87ba70043bfc Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents: 17198
diff changeset
77 oldfig = get (0, "currentfigure");
87ba70043bfc Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents: 17198
diff changeset
78 endif
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
79 unwind_protect
17069
1cbdd14711c5 scatter3.m, scatter.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14359
diff changeset
80 hax = newplot (hax);
1cbdd14711c5 scatter3.m, scatter.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14359
diff changeset
81
1cbdd14711c5 scatter3.m, scatter.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14359
diff changeset
82 tmp = __scatter__ (hax, 3, "scatter3", varargin{:});
17130
26589abbc78d Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents: 17126
diff changeset
83
26589abbc78d Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents: 17126
diff changeset
84 if (! ishold (hax))
26589abbc78d Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents: 17126
diff changeset
85 set (hax, "view", [-37.5, 30],
26589abbc78d Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents: 17126
diff changeset
86 "xgrid", "on", "ygrid", "on", "zgrid", "on");
26589abbc78d Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents: 17126
diff changeset
87 endif
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
88 unwind_protect_cleanup
17069
1cbdd14711c5 scatter3.m, scatter.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14359
diff changeset
89 if (! isempty (oldfig))
1cbdd14711c5 scatter3.m, scatter.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14359
diff changeset
90 set (0, "currentfigure", oldfig);
1cbdd14711c5 scatter3.m, scatter.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14359
diff changeset
91 endif
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
92 end_unwind_protect
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
93 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
94
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
95 if (nargout > 0)
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
96 retval = tmp;
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
97 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
98
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
99 endfunction
7245
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7215
diff changeset
100
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
101
7245
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7215
diff changeset
102 %!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
103 %! clf;
7245
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7215
diff changeset
104 %! [x, y, z] = peaks (20);
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7215
diff changeset
105 %! scatter3 (x(:), y(:), z(:), [], z(:));
17198
df4c4b7708a4 Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents: 17130
diff changeset
106 %! title ({'Default scatter3() plot', ...
df4c4b7708a4 Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents: 17130
diff changeset
107 %! 'constant size bubbles and color determined by Z'});
9295
10b9a71a81f1 __scatter__.m: If the color spec is empty, set using __next_line_color__.
Ben Abbott <bpabbott@mac.com>
parents: 9245
diff changeset
108
10b9a71a81f1 __scatter__.m: If the color spec is empty, set using __next_line_color__.
Ben Abbott <bpabbott@mac.com>
parents: 9245
diff changeset
109 %!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
110 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
111 %! x = rand (20,1); y = rand (20,1); z = rand (20,1);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
112 %! scatter3 (x(:), y(:), z(:), 10, z(:), 's');
17198
df4c4b7708a4 Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents: 17130
diff changeset
113 %! title ({'scatter3() plot', ...
df4c4b7708a4 Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents: 17130
diff changeset
114 %! 'marker is square, size is 10, color determined by Z'});
9295
10b9a71a81f1 __scatter__.m: If the color spec is empty, set using __next_line_color__.
Ben Abbott <bpabbott@mac.com>
parents: 9245
diff changeset
115
10b9a71a81f1 __scatter__.m: If the color spec is empty, set using __next_line_color__.
Ben Abbott <bpabbott@mac.com>
parents: 9245
diff changeset
116 %!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
117 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
118 %! x = rand (20,1); y = rand (20,1); z = rand (20,1);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
119 %! scatter3 (x(:), y(:), z(:), 20*z(:), [], 's');
17198
df4c4b7708a4 Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents: 17130
diff changeset
120 %! title ({'scatter3() plot', ...
df4c4b7708a4 Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents: 17130
diff changeset
121 %! 'marker is square, size is determined by Z'});
9295
10b9a71a81f1 __scatter__.m: If the color spec is empty, set using __next_line_color__.
Ben Abbott <bpabbott@mac.com>
parents: 9245
diff changeset
122
10b9a71a81f1 __scatter__.m: If the color spec is empty, set using __next_line_color__.
Ben Abbott <bpabbott@mac.com>
parents: 9245
diff changeset
123 %!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
124 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
125 %! x = rand (20,1); y = rand (20,1); z = rand (20,1);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
126 %! scatter3 (x(:), y(:), z(:), 20*z(:), z(:), 's');
17198
df4c4b7708a4 Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents: 17130
diff changeset
127 %! title ({'scatter3() plot', ...
df4c4b7708a4 Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents: 17130
diff changeset
128 %! 'marker is square, size and color determined by Z'});
9295
10b9a71a81f1 __scatter__.m: If the color spec is empty, set using __next_line_color__.
Ben Abbott <bpabbott@mac.com>
parents: 9245
diff changeset
129