]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/scatter.m
update packages
[CreaPhase.git] / octave_packages / m / plot / scatter.m
1 ## Copyright (C) 2007-2012 David Bateman
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 -*-
20 ## @deftypefn  {Function File} {} scatter (@var{x}, @var{y})
21 ## @deftypefnx {Function File} {} scatter (@var{x}, @var{y}, @var{s})
22 ## @deftypefnx {Function File} {} scatter (@var{x}, @var{y}, @var{c})
23 ## @deftypefnx {Function File} {} scatter (@var{x}, @var{y}, @var{s}, @var{c})
24 ## @deftypefnx {Function File} {} scatter (@var{x}, @var{y}, @var{s}, @var{c}, @var{style})
25 ## @deftypefnx {Function File} {} scatter (@var{x}, @var{y}, @var{s}, @var{c}, @var{prop}, @var{val})
26 ## @deftypefnx {Function File} {} scatter (@dots{}, "filled")
27 ## @deftypefnx {Function File} {} scatter (@var{h}, @dots{})
28 ## @deftypefnx {Function File} {@var{h} =} scatter (@dots{})
29 ##
30 ## Plot a scatter plot of the data.  A marker is plotted at each point
31 ## defined by the points in the vectors @var{x} and @var{y}.  The size of
32 ## the markers used is determined by the @var{s}, which can be a scalar,
33 ## a vector of the same length of @var{x} and @var{y}.  If @var{s} is not
34 ## given or is an empty matrix, then the default value of 8 points is used.
35 ##
36 ## The color of the markers is determined by @var{c}, which can be a string
37 ## defining a fixed color; a 3-element vector giving the red, green,and blue
38 ## components of the color; a vector of the same length as @var{x} that gives
39 ## a scaled index into the current colormap; or a @var{n}-by-3 matrix defining
40 ## the colors of each of the markers individually.
41 ##
42 ## The marker to use can be changed with the @var{style} argument, that is a
43 ## string defining a marker in the same manner as the @code{plot} command.
44 ## If the argument @code{"filled"} is given then the markers as filled.  All
45 ## additional arguments are passed to the underlying patch command.
46 ##
47 ## The optional return value @var{h} provides a handle to the patch object
48 ##
49 ## @example
50 ## @group
51 ## x = randn (100, 1);
52 ## y = randn (100, 1);
53 ## scatter (x, y, [], sqrt(x.^2 + y.^2));
54 ## @end group
55 ## @end example
56 ##
57 ## @seealso{plot, patch, scatter3}
58 ## @end deftypefn
59
60 function retval = scatter (varargin)
61
62   [h, varargin, nargin] = __plt_get_axis_arg__ ("scatter", varargin{:});
63
64   if (nargin < 2)
65     print_usage ();
66   else
67     oldh = gca ();
68     unwind_protect
69       axes (h);
70       newplot ();
71       tmp = __scatter__ (h, 2, "scatter", varargin{:});
72     unwind_protect_cleanup
73       axes (oldh);
74     end_unwind_protect
75   endif
76
77   if (nargout > 0)
78     retval = tmp;
79   endif
80
81 endfunction
82
83
84 %!demo
85 %! clf
86 %! x = randn (100, 1);
87 %! y = randn (100, 1);
88 %! scatter (x, y, "r");
89
90 %!demo
91 %! clf
92 %! x = randn (100, 1);
93 %! y = randn (100, 1);
94 %! scatter (x, y, [], sqrt (x.^2 + y.^2));
95
96 %!demo
97 %! clf
98 %! rand_10x1_data1 = [0.171577, 0.404796, 0.025469, 0.335309, 0.047814, 0.898480, 0.639599, 0.700247, 0.497798, 0.737940];
99 %! rand_10x1_data2 = [0.75495, 0.83991, 0.80850, 0.73603, 0.19360, 0.72573, 0.69371, 0.74388, 0.13837, 0.54143];
100 %! x = rand_10x1_data1;
101 %! y = rand_10x1_data2;
102 %! s = 10 - 10*log (x.^2 + y.^2);
103 %! h = scatter (x, y, s, s, "s", "filled");
104
105 %!demo
106 %! clf
107 %! rand_10x1_data3 = [0.42262, 0.51623, 0.65992, 0.14999, 0.68385, 0.55929, 0.52251, 0.92204, 0.19762, 0.93726];
108 %! rand_10x1_data4 = [0.020207, 0.527193, 0.443472, 0.061683, 0.370277, 0.947349, 0.249591, 0.666304, 0.134247, 0.920356];
109 %! x = rand_10x1_data3;
110 %! y = rand_10x1_data4;
111 %! s = 10 - 10*log (x.^2 + y.^2);
112 %! h = scatter (x, y, [], "r", "s", "filled");
113
114 %!demo
115 %! clf
116 %! rand_10x1_data5 = [0.777753, 0.093848, 0.183162, 0.399499, 0.337997, 0.686724, 0.073906, 0.651808, 0.869273, 0.137949];
117 %! rand_10x1_data6 = [0.37460, 0.25027, 0.19510, 0.51182, 0.54704, 0.56087, 0.24853, 0.75443, 0.42712, 0.44273];
118 %! x = rand_10x1_data5;
119 %! y = rand_10x1_data6;
120 %! s = 10 - 10*log (x.^2 + y.^2);
121 %! h = scatter (x, y, [], "r", "s");
122
123 %!demo
124 %! k = 1;
125 %! clf
126 %! for m = [1, 3]
127 %!   for n = [101, 50, 1]
128 %!     x = rand (n, 1);
129 %!     y = rand (n, 1);
130 %!     if (m > 1)
131 %!       str = "Three Colors";
132 %!       idx = ceil (rand (n, 1) * 3);
133 %!       colors = eye(3);
134 %!       colors = colors(idx, :);
135 %!     else
136 %!       str = "Random Colors";
137 %!       colors = rand (n, m);
138 %!     endif
139 %!     if (n == 1)
140 %!       str = sprintf ("%s: 1 point", str);
141 %!     elseif (n < 100)
142 %!       str = sprintf ("%s: < 100 points", str);
143 %!     else
144 %!       str = sprintf ("%s: > 100 points", str);
145 %!     endif
146 %!     subplot (2, 3, k)
147 %!     k = k + 1;
148 %!     scatter (x, y, 15, colors, "filled")
149 %!     axis ([0 1 0 1])
150 %!     title (str)
151 %!   endfor
152 %! endfor
153
154 %!demo
155 %! k = 1;
156 %! clf
157 %! for m = [1, 3]
158 %!   for n = [101, 50, 1]
159 %!     x = rand (n, 1);
160 %!     y = rand (n, 1);
161 %!     if (m > 1)
162 %!       str = "Three Colors";
163 %!       idx = ceil (rand (n, 1) * 3);
164 %!       colors = eye(3);
165 %!       colors = colors(idx, :);
166 %!     else
167 %!       str = "Random Colors";
168 %!       colors = rand (n, m);
169 %!     endif
170 %!     if (n == 1)
171 %!       str = sprintf ("%s: 1 point", str);
172 %!     elseif (n < 100)
173 %!       str = sprintf ("%s: < 100 points", str);
174 %!     else
175 %!       str = sprintf ("%s: > 100 points", str);
176 %!     endif
177 %!     subplot (2, 3, k)
178 %!     k = k + 1;
179 %!     scatter (x, y, 15, colors)
180 %!     axis ([0 1 0 1])
181 %!     title (str)
182 %!   endfor
183 %! endfor