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