comparison scripts/plot/draw/private/__scatter__.m @ 17572:7bb76a22cde1

maint: Split scripts/plot directory into 4 pieces. scripts/gui : user-interface functions scripts/plot/appearance : functions controlling plot appearance scripts/plot/draw : plotting functions which produce graphs scripts/plot/util : low-level plotting functions and utilities. * scripts/gui/guidata.m, scripts/gui/guihandles.m, scripts/gui/module.mk, scripts/gui/private/__file_filter__.m, scripts/gui/private/__fltk_file_filter__.m, scripts/gui/private/__is_function__.m, scripts/gui/private/__uigetdir_fltk__.m, scripts/gui/private/__uigetfile_fltk__.m, scripts/gui/private/__uiobject_split_args__.m, scripts/gui/private/__uiputfile_fltk__.m, scripts/gui/uicontextmenu.m, scripts/gui/uicontrol.m, scripts/gui/uigetdir.m, scripts/gui/uigetfile.m, scripts/gui/uimenu.m, scripts/gui/uipanel.m, scripts/gui/uipushtool.m, scripts/gui/uiputfile.m, scripts/gui/uiresume.m, scripts/gui/uitoggletool.m, scripts/gui/uitoolbar.m, scripts/gui/uiwait.m, scripts/gui/waitbar.m, scripts/gui/waitforbuttonpress.m: Moved from scripts/plot to scripts/gui * scripts/plot/appearance/__clabel__.m, scripts/plot/appearance/__getlegenddata__.m, scripts/plot/appearance/axis.m, scripts/plot/appearance/box.m, scripts/plot/appearance/caxis.m, scripts/plot/appearance/clabel.m, scripts/plot/appearance/daspect.m, scripts/plot/appearance/diffuse.m, scripts/plot/appearance/grid.m, scripts/plot/appearance/gtext.m, scripts/plot/appearance/hidden.m, scripts/plot/appearance/legend.m, scripts/plot/appearance/orient.m, scripts/plot/appearance/pbaspect.m, scripts/plot/appearance/private/__axis_label__.m, scripts/plot/appearance/private/__axis_limits__.m, scripts/plot/appearance/shading.m, scripts/plot/appearance/specular.m, scripts/plot/appearance/text.m, scripts/plot/appearance/title.m, scripts/plot/appearance/view.m, scripts/plot/appearance/whitebg.m, scripts/plot/appearance/xlabel.m, scripts/plot/appearance/xlim.m, scripts/plot/appearance/ylabel.m, scripts/plot/appearance/ylim.m, scripts/plot/appearance/zlabel.m, scripts/plot/appearance/zlim.m: Moved from scripts/plot to subdir appearance. * scripts/plot/draw/area.m, scripts/plot/draw/bar.m, scripts/plot/draw/barh.m, scripts/plot/draw/colorbar.m, scripts/plot/draw/comet.m, scripts/plot/draw/comet3.m, scripts/plot/draw/compass.m, scripts/plot/draw/contour.m, scripts/plot/draw/contour3.m, scripts/plot/draw/contourc.m, scripts/plot/draw/contourf.m, scripts/plot/draw/cylinder.m, scripts/plot/draw/ellipsoid.m, scripts/plot/draw/errorbar.m, scripts/plot/draw/ezcontour.m, scripts/plot/draw/ezcontourf.m, scripts/plot/draw/ezmesh.m, scripts/plot/draw/ezmeshc.m, scripts/plot/draw/ezplot.m, scripts/plot/draw/ezplot3.m, scripts/plot/draw/ezpolar.m, scripts/plot/draw/ezsurf.m, scripts/plot/draw/ezsurfc.m, scripts/plot/draw/feather.m, scripts/plot/draw/fill.m, scripts/plot/draw/fplot.m, scripts/plot/draw/hist.m, scripts/plot/draw/isocolors.m, scripts/plot/draw/isonormals.m, scripts/plot/draw/isosurface.m, scripts/plot/draw/line.m, scripts/plot/draw/loglog.m, scripts/plot/draw/loglogerr.m, scripts/plot/draw/mesh.m, scripts/plot/draw/meshc.m, scripts/plot/draw/meshz.m, scripts/plot/draw/pareto.m, scripts/plot/draw/patch.m, scripts/plot/draw/pcolor.m, scripts/plot/draw/peaks.m, scripts/plot/draw/pie.m, scripts/plot/draw/pie3.m, scripts/plot/draw/plot.m, scripts/plot/draw/plot3.m, scripts/plot/draw/plotmatrix.m, scripts/plot/draw/plotyy.m, scripts/plot/draw/polar.m, scripts/plot/draw/private/__add_datasource__.m, scripts/plot/draw/private/__bar__.m, scripts/plot/draw/private/__contour__.m, scripts/plot/draw/private/__errcomm__.m, scripts/plot/draw/private/__errplot__.m, scripts/plot/draw/private/__ezplot__.m, scripts/plot/draw/private/__interp_cube__.m, scripts/plot/draw/private/__line__.m, scripts/plot/draw/private/__marching_cube__.m, scripts/plot/draw/private/__patch__.m, scripts/plot/draw/private/__pie__.m, scripts/plot/draw/private/__plt__.m, scripts/plot/draw/private/__quiver__.m, scripts/plot/draw/private/__scatter__.m, scripts/plot/draw/private/__stem__.m, scripts/plot/draw/quiver.m, scripts/plot/draw/quiver3.m, scripts/plot/draw/rectangle.m, scripts/plot/draw/ribbon.m, scripts/plot/draw/rose.m, scripts/plot/draw/scatter.m, scripts/plot/draw/scatter3.m, scripts/plot/draw/semilogx.m, scripts/plot/draw/semilogxerr.m, scripts/plot/draw/semilogy.m, scripts/plot/draw/semilogyerr.m, scripts/plot/draw/shrinkfaces.m, scripts/plot/draw/slice.m, scripts/plot/draw/sombrero.m, scripts/plot/draw/sphere.m, scripts/plot/draw/stairs.m, scripts/plot/draw/stem.m, scripts/plot/draw/stem3.m, scripts/plot/draw/stemleaf.m, scripts/plot/draw/surf.m, scripts/plot/draw/surface.m, scripts/plot/draw/surfc.m, scripts/plot/draw/surfl.m, scripts/plot/draw/surfnorm.m, scripts/plot/draw/tetramesh.m, scripts/plot/draw/trimesh.m, scripts/plot/draw/triplot.m, scripts/plot/draw/trisurf.m, scripts/plot/draw/waterfall.m: Moved from plot/ to subdir draw. * scripts/plot/util/__actual_axis_position__.m, scripts/plot/util/__default_plot_options__.m, scripts/plot/util/__gnuplot_drawnow__.m, scripts/plot/util/__next_line_color__.m, scripts/plot/util/__next_line_style__.m, scripts/plot/util/__plt_get_axis_arg__.m, scripts/plot/util/__pltopt__.m, scripts/plot/util/allchild.m, scripts/plot/util/ancestor.m, scripts/plot/util/axes.m, scripts/plot/util/cla.m, scripts/plot/util/clf.m, scripts/plot/util/close.m, scripts/plot/util/closereq.m, scripts/plot/util/colstyle.m, scripts/plot/util/copyobj.m, scripts/plot/util/figure.m, scripts/plot/util/findall.m, scripts/plot/util/findfigs.m, scripts/plot/util/findobj.m, scripts/plot/util/gca.m, scripts/plot/util/gcbf.m, scripts/plot/util/gcbo.m, scripts/plot/util/gcf.m, scripts/plot/util/gco.m, scripts/plot/util/ginput.m, scripts/plot/util/gnuplot_binary.in, scripts/plot/util/graphics_toolkit.m, scripts/plot/util/hdl2struct.m, scripts/plot/util/hggroup.m, scripts/plot/util/hold.m, scripts/plot/util/isaxes.m, scripts/plot/util/isfigure.m, scripts/plot/util/ishghandle.m, scripts/plot/util/ishold.m, scripts/plot/util/isprop.m, scripts/plot/util/linkprop.m, scripts/plot/util/meshgrid.m, scripts/plot/util/ndgrid.m, scripts/plot/util/newplot.m, scripts/plot/util/print.m, scripts/plot/util/printd.m, scripts/plot/util/private/__add_default_menu__.m, scripts/plot/util/private/__fltk_ginput__.m, scripts/plot/util/private/__fltk_print__.m, scripts/plot/util/private/__ghostscript__.m, scripts/plot/util/private/__gnuplot_get_var__.m, scripts/plot/util/private/__gnuplot_ginput__.m, scripts/plot/util/private/__gnuplot_has_feature__.m, scripts/plot/util/private/__gnuplot_has_terminal__.m, scripts/plot/util/private/__gnuplot_open_stream__.m, scripts/plot/util/private/__gnuplot_print__.m, scripts/plot/util/private/__gnuplot_version__.m, scripts/plot/util/private/__go_draw_axes__.m, scripts/plot/util/private/__go_draw_figure__.m, scripts/plot/util/private/__print_parse_opts__.m, scripts/plot/util/private/__tight_eps_bbox__.m, scripts/plot/util/refresh.m, scripts/plot/util/refreshdata.m, scripts/plot/util/saveas.m, scripts/plot/util/shg.m, scripts/plot/util/struct2hdl.m, scripts/plot/util/subplot.m: Moved from plot to subdir util. * etc/HACKING: Updated directory structure info. * scripts/Makefile.am, scripts/plot/appearance/module.mk, scripts/plot/draw/module.mk, scripts/plot/util/module.mk: Added new directories to build system.
author Rik <rik@octave.org>
date Fri, 04 Oct 2013 17:09:08 -0700
parents scripts/plot/private/__scatter__.m@76614e624818
children d63878346099
comparison
equal deleted inserted replaced
17571:6e4ea5c8a4bb 17572:7bb76a22cde1
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} {@var{hg} =} __scatter__ (@dots{})
21 ## Undocumented internal function.
22 ## @end deftypefn
23
24 function hg = __scatter__ (varargin)
25
26 hax = varargin{1}; # We don't do anything with this. Could remove it.
27 nd = varargin{2};
28 fcn = varargin{3};
29 x = varargin{4}(:);
30 y = varargin{5}(:);
31
32 if (nd == 2)
33 istart = 6;
34 else
35 z = varargin{6}(:);
36 istart = 7;
37 endif
38
39 if (istart <= nargin)
40 s = varargin{istart}(:);
41 if (isempty (s) || ischar (s))
42 s = 6;
43 endif
44 if (! ischar (varargin{istart}))
45 istart++;
46 endif
47 else
48 s = 6;
49 endif
50
51 ## Remove NaNs
52 idx = isnan (x) | isnan (y) | isnan (s);
53 if (nd == 3)
54 idx |= isnan (z);
55 z(idx) = [];
56 endif
57 x(idx) = [];
58 y(idx) = [];
59 if (nd == 2)
60 z = zeros (length (x), 0);
61 endif
62 if (numel (s) > 1)
63 s(idx) = [];
64 endif
65
66 firstnonnumeric = find (! cellfun ("isnumeric", varargin(istart:nargin)), 1);
67 if (isempty (firstnonnumeric))
68 firstnonnumeric = Inf;
69 else
70 firstnonnumeric += istart - 1;
71 endif
72
73 if (istart <= nargin && firstnonnumeric > istart)
74 c = varargin{istart};
75 if (isvector (c) && columns (c) != 3)
76 c = c(:);
77 endif
78 elseif (firstnonnumeric == istart && ischar (varargin{istart})
79 && ! ( strcmpi (varargin{istart}, "filled")
80 || strcmpi (varargin{istart}, "fill")))
81 c = varargin{istart};
82 firstnonnumeric++;
83 else
84 c = [];
85 endif
86
87 newargs = {};
88 filled = false;
89 have_marker = false;
90 marker = "o";
91 iarg = firstnonnumeric;
92 while (iarg <= nargin)
93 arg = varargin{iarg++};
94 if (ischar (arg) && (strcmpi (arg, "filled") || strcmpi (arg, "fill")))
95 filled = true;
96 elseif ((ischar (arg) || iscellstr (arg)) && ! have_marker)
97 [linespec, valid] = __pltopt__ (fcn, arg, false);
98 if (valid)
99 have_marker = true;
100 marker = linespec.marker;
101 if (strcmp (marker, "none"))
102 marker = "o";
103 elseif (isempty (marker))
104 have_marker = false;
105 [~, marker] = __next_line_style__ ();
106 endif
107 else
108 error ("%s: invalid linespec", fcn);
109 endif
110 else
111 newargs{end+1} = arg;
112 if (iarg <= nargin)
113 newargs{end+1} = varargin{iarg++};
114 endif
115 endif
116 endwhile
117
118 if (isempty (c))
119 c = __next_line_color__ ();
120 endif
121
122 ## Must occur after __next_line_color__ in order to work correctly.
123 hg = hggroup ();
124 newargs = __add_datasource__ (fcn, hg, {"x", "y", "z", "c", "size"},
125 newargs{:});
126
127 addproperty ("xdata", hg, "data", x);
128 addproperty ("ydata", hg, "data", y);
129 addproperty ("zdata", hg, "data", z);
130 if (ischar (c))
131 ## For single explicit color, cdata is unused
132 addproperty ("cdata", hg, "data", []);
133 else
134 addproperty ("cdata", hg, "data", c);
135 endif
136 addproperty ("sizedata", hg, "data", s);
137 addlistener (hg, "xdata", @update_data);
138 addlistener (hg, "ydata", @update_data);
139 addlistener (hg, "zdata", @update_data);
140 addlistener (hg, "cdata", @update_data);
141 addlistener (hg, "sizedata", @update_data);
142
143 one_explicit_color = ischar (c) || isequal (size (c), [1, 3]);
144
145 if (numel (x) <= 100)
146
147 ## For small number of points, we'll construct an object for each point.
148
149 if (numel (s) == 1)
150 s = repmat (s, numel (x), 1);
151 endif
152
153 if (one_explicit_color)
154 for i = 1 : numel (x)
155 if (filled)
156 __go_patch__ (hg, "xdata", x(i), "ydata", y(i), "zdata", z(i,:),
157 "faces", 1, "vertices", [x(i), y(i), z(i,:)],
158 "facecolor", "none", "edgecolor", "none",
159 "marker", marker, "markersize", s(i),
160 "markeredgecolor", c, "markerfacecolor", c,
161 "linestyle", "none");
162 else
163 __go_patch__ (hg, "xdata", x(i), "ydata", y(i), "zdata", z(i,:),
164 "faces", 1, "vertices", [x(i), y(i), z(i,:)],
165 "facecolor", "none", "edgecolor", "none",
166 "marker", marker, "markersize", s(i),
167 "markeredgecolor", c, "markerfacecolor", "none",
168 "linestyle", "none");
169 endif
170 endfor
171 else
172 if (rows (c) == 1)
173 c = repmat (c, rows (x), 1);
174 endif
175 for i = 1 : numel (x)
176 if (filled)
177 __go_patch__ (hg, "xdata", x(i), "ydata", y(i), "zdata", z(i,:),
178 "faces", 1, "vertices", [x(i), y(i), z(i,:)],
179 "facecolor", "none", "edgecolor", "none",
180 "marker", marker, "markersize", s(i),
181 "markeredgecolor", "none",
182 "markerfacecolor", "flat",
183 "cdata", c(i,:), "facevertexcdata", c(i,:),
184 "linestyle", "none");
185 else
186 __go_patch__ (hg, "xdata", x(i), "ydata", y(i), "zdata", z(i,:),
187 "faces", 1, "vertices", [x(i), y(i), z(i,:)],
188 "facecolor", "none", "edgecolor", "none",
189 "marker", marker, "markersize", s(i),
190 "markeredgecolor", "flat",
191 "markerfacecolor", "none",
192 "cdata", c(i,:), "facevertexcdata", c(i,:),
193 "linestyle", "none");
194 endif
195 endfor
196 endif
197
198 else
199
200 ## For larger numbers of points, we split the points by common color.
201
202 vert = [x, y, z];
203 if (one_explicit_color)
204 render_size_color (hg, vert, s, c, marker, filled, true);
205 else
206 if (rows (c) == 1)
207 c = repmat (c, rows (x), 1);
208 endif
209 ## We want to group points by color. So first get all the unique colors
210 [cc, ~, c_to_cc] = unique (c, "rows");
211
212 for i = 1 : rows (cc)
213 ## Now for each possible unique color, get the logical index of
214 ## points that correspond to that color
215 idx = (i == c_to_cc);
216 if (isscalar (s))
217 render_size_color (hg, vert(idx, :), s, c(idx,:),
218 marker, filled, true);
219 else
220 render_size_color (hg, vert(idx, :), s(idx), c(idx,:),
221 marker, filled, true);
222 endif
223 endfor
224
225 endif
226 endif
227
228 if (! ischar (c) && rows (c) > 1)
229 ax = get (hg, "parent");
230 clim = get (ax, "clim");
231 if (min (c(:)) < clim(1))
232 clim(1) = min (c(:));
233 set (ax, "clim", clim);
234 endif
235 if (max (c(:)) > clim(2))
236 set (ax, "clim", [clim(1), max(c(:))]);
237 endif
238 endif
239
240 addproperty ("linewidth", hg, "patchlinewidth", 0.5);
241 addproperty ("marker", hg, "patchmarker", marker);
242 if (filled)
243 addproperty ("markeredgecolor", hg, "patchmarkeredgecolor", "none");
244 if (one_explicit_color)
245 addproperty ("markerfacecolor", hg, "patchmarkerfacecolor", c);
246 else
247 addproperty ("markerfacecolor", hg, "patchmarkerfacecolor", "flat");
248 endif
249 else
250 addproperty ("markerfacecolor", hg, "patchmarkerfacecolor", "none");
251 if (one_explicit_color)
252 addproperty ("markeredgecolor", hg, "patchmarkeredgecolor", c);
253 else
254 addproperty ("markeredgecolor", hg, "patchmarkeredgecolor", "flat");
255 endif
256 endif
257 addlistener (hg, "linewidth", @update_props);
258 addlistener (hg, "marker", @update_props);
259 addlistener (hg, "markerfacecolor", @update_props);
260 addlistener (hg, "markeredgecolor", @update_props);
261
262 ## Matlab property, although Octave does not implement it.
263 addproperty ("hittestarea", hg, "radio", "on|{off}", "off");
264
265 if (! isempty (newargs))
266 set (hg, newargs{:});
267 endif
268
269 endfunction
270
271 function render_size_color (hg, vert, s, c, marker, filled, isflat)
272 if (isscalar (s))
273 x = vert(:,1);
274 y = vert(:,2);
275 z = vert(:,3:end);
276 toolkit = get (ancestor (hg, "figure"), "__graphics_toolkit__");
277 ## Does gnuplot only support triangles with different vertex colors ?
278 ## TODO: Verify gnuplot can only support one color. If RGB triplets
279 ## can be assigned to each vertex, then fix __go_draw_axes__.m
280 gnuplot_hack = (numel (x) > 1 && columns (c) == 3
281 && strcmp (toolkit, "gnuplot"));
282 if (ischar (c) || ! isflat || gnuplot_hack)
283 if (filled)
284 __go_patch__ (hg, "xdata", x, "ydata", y, "zdata", z,
285 "faces", 1:numel (x), "vertices", vert,
286 "facecolor", "none", "edgecolor", "none",
287 "marker", marker,
288 "markeredgecolor", "none",
289 "markerfacecolor", c(1,:),
290 "markersize", s, "linestyle", "none");
291 else
292 __go_patch__ (hg, "xdata", x, "ydata", y, "zdata", z,
293 "faces", 1:numel (x), "vertices", vert,
294 "facecolor", "none", "edgecolor", "none",
295 "marker", marker,
296 "markeredgecolor", c(1,:),
297 "markerfacecolor", "none",
298 "markersize", s, "linestyle", "none");
299 endif
300 else
301 if (filled)
302 __go_patch__ (hg, "xdata", x, "ydata", y, "zdata", z,
303 "faces", 1:numel (x), "vertices", vert,
304 "facecolor", "none", "edgecolor", "none",
305 "marker", marker, "markersize", s,
306 "markeredgecolor", "none",
307 "markerfacecolor", "flat",
308 "cdata", c, "facevertexcdata", c,
309 "linestyle", "none");
310 else
311 __go_patch__ (hg, "xdata", x, "ydata", y, "zdata", z,
312 "faces", 1:numel (x), "vertices", vert,
313 "facecolor", "none", "edgecolor", "none",
314 "marker", marker, "markersize", s,
315 "markeredgecolor", "flat",
316 "markerfacecolor", "none",
317 "cdata", c, "facevertexcdata", c,
318 "linestyle", "none");
319 endif
320 endif
321 else
322 ## Round size to one decimal place.
323 [ss, ~, s_to_ss] = unique (ceil (s*10) / 10);
324 for i = 1:rows (ss)
325 idx = (i == s_to_ss);
326 render_size_color (hg, vert(idx,:), ss(i), c,
327 marker, filled, isflat);
328 endfor
329 endif
330 endfunction
331
332 function update_props (h, d)
333 lw = get (h, "linewidth");
334 m = get (h, "marker");
335 fc = get (h, "markerfacecolor");
336 ec = get (h, "markeredgecolor");
337 kids = get (h, "children");
338
339 set (kids, "linewidth", lw, "marker", m,
340 "markerfacecolor", fc, "markeredgecolor", ec);
341 endfunction
342
343 function update_data (h, d)
344 x = get (h, "xdata");
345 y = get (h, "ydata");
346 z = get (h, "zdata");
347 c = get (h, "cdata");
348 if (rows (c) == 1)
349 c = repmat (c, numel (x), 1);
350 endif
351 s = get (h, "sizedata");
352 if (numel (s) == 1)
353 s = repmat (s, numel (x), 1);
354 endif
355 hlist = get (h, "children");
356
357 if (isempty (z))
358 for i = 1 : length (hlist)
359 set (hlist(i), "vertices", [x(i), y(i)],
360 "cdata", reshape (c(i,:),[1, size(c)(2:end)]),
361 "facevertexcdata", c(i,:),
362 "markersize", s(i));
363 endfor
364 else
365 for i = 1 : length (hlist)
366 set (hlist(i), "vertices", [x(i), y(i), z(i)],
367 "cdata", reshape (cd(i,:),[1, size(cd)(2:end)]),
368 "facevertexcdata", cd(i,:),
369 "markersize", s(i));
370 endfor
371 endif
372
373 endfunction
374