7189
|
1 ## Copyright (C) 2007 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 ## Undocumented internal function. |
|
20 |
|
21 function h = __scatter__ (varargin) |
7191
|
22 |
|
23 h = varargin{1}; |
|
24 nd = varargin{2}; |
|
25 fcn = varargin{3}; |
|
26 x = varargin{4}(:); |
|
27 y = varargin{5}(:); |
7189
|
28 istart = 6; |
7191
|
29 |
7189
|
30 if (nd == 3) |
7191
|
31 z = varargin{6}(:); |
7421
|
32 idx = isnan(x) | isnan (y) | isnan (z); |
|
33 x (idx) = []; |
|
34 y (idx) = []; |
|
35 z (idx) = []; |
7189
|
36 istart = 7; |
|
37 else |
7421
|
38 idx = isnan(x) | isnan (y); |
|
39 x (idx) = []; |
|
40 y (idx) = []; |
7191
|
41 z = zeros (length (x), 0); |
7189
|
42 endif |
|
43 |
|
44 firstnonnumeric = Inf; |
|
45 for i = istart:nargin |
7191
|
46 if (! isnumeric (varargin{i})) |
7189
|
47 firstnonnumeric = i; |
|
48 break; |
|
49 endif |
|
50 endfor |
|
51 |
7235
|
52 if (istart < nargin && firstnonnumeric > istart) |
7191
|
53 s = varargin{istart}; |
7189
|
54 if (isempty (s)) |
|
55 s = 8; |
|
56 endif |
|
57 else |
|
58 s = 8; |
|
59 endif |
|
60 ## Note markersize is in points^2 for 2D and points for 3D, and |
|
61 ## the below is an approximation, that is empircally visually correct. |
|
62 if (nd == 2) |
|
63 s = sqrt (s) / 2; |
|
64 else |
|
65 s = s / 4; |
|
66 endif |
|
67 |
|
68 if (istart < nargin && firstnonnumeric > istart + 1) |
7191
|
69 c = varargin{istart + 1}; |
7189
|
70 if (isvector (c)) |
|
71 c = c(:); |
|
72 endif |
7191
|
73 elseif (firstnonnumeric == istart + 1 && ischar (varargin{istart + 1})) |
7189
|
74 c = varargin{istart + 1}; |
|
75 firstnonnumeric++; |
|
76 else |
|
77 c = 1 : length(x); |
|
78 endif |
|
79 |
|
80 newargs = {}; |
|
81 filled = false; |
|
82 have_marker = false; |
|
83 marker = "o"; |
|
84 iarg = firstnonnumeric; |
|
85 while (iarg <= nargin) |
7191
|
86 arg = varargin{iarg++}; |
7189
|
87 if (ischar (arg) && strncmp (tolower (arg), "filled", 6)) |
|
88 filled = true; |
|
89 elseif ((isstr (arg) || iscell (arg)) && ! have_marker) |
|
90 [linespec, valid] = __pltopt__ ("scatter", arg, false); |
|
91 if (valid) |
|
92 have_marker = true; |
|
93 marker = linespec.marker; |
|
94 if (strncmp (marker, "none", 4)) |
|
95 marker = "o"; |
|
96 endif |
|
97 else |
|
98 error ("scatter: invalid linespec"); |
|
99 endif |
|
100 else |
|
101 newargs{end+1} = arg; |
|
102 if (iarg <= nargin) |
|
103 newargs{end+1} = varagin{iarg++}; |
|
104 endif |
|
105 endif |
|
106 endwhile |
|
107 |
|
108 if (ischar (c)) |
7191
|
109 h = patch("faces", [1:length(x)].', "vertices", [x, y, z], "facecolor", |
|
110 "none", "edgecolor", c, "marker", marker, |
|
111 "markersize", s, "linestyle", "none"); |
7189
|
112 if (filled) |
7191
|
113 set(h, "markerfacecolor", c); |
7189
|
114 endif |
|
115 else |
7191
|
116 h = patch("faces", [1:length(x)].', "vertices", [x, y, z], "facecolor", |
|
117 "none", "edgecolor", "flat", "cdata", c, "marker", marker, |
|
118 "markersize", s, "linestyle", "none"); |
7189
|
119 if (filled) |
7191
|
120 set(h, "markerfacecolor", "flat"); |
7189
|
121 endif |
|
122 ax = get (h, "parent"); |
|
123 clim = get (ax, "clim"); |
|
124 if (min(c(:)) < clim(1)) |
|
125 clim(1) = min(c(:)); |
|
126 set (ax, "clim", clim); |
|
127 endif |
|
128 if (max(c(:)) > clim(2)) |
|
129 set (ax, "clim", [clim(1), max(c(:))]); |
|
130 endif |
|
131 endif |
|
132 |
|
133 endfunction |