1 ## Copyright (C) 1993-2012 John W. Eaton
3 ## This file is part of Octave.
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.
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.
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/>.
20 ## @deftypefn {Function File} {} __plt__ (@var{caller}, @var{h}, @var{varargin})
21 ## Undocumented internal function.
26 function retval = __plt__ (caller, h, varargin)
40 fkids = get (gcf(), "children");
41 for i = 1 : numel(fkids)
42 if (ishandle (fkids (i)) && strcmp (get (fkids (i), "type"), "axes")
43 && (strcmp (get (fkids (i), "tag"), "legend")))
44 udata = get (fkids (i), "userdata");
45 if (! isempty (intersect (udata.handle, gca ())))
53 if (isempty (hlegend))
57 [hlgnd, tlgnd] = __getlegenddata__ (hlegend);
60 ## Gather arguments, decode format, gather plot strings, and plot lines.
64 while (nargs > 0 || x_set)
67 ## Force the last plot when input variables run out.
71 next_cell = varargin(k);
72 next_arg = varargin{k++};
77 if (ischar (next_arg) || iscellstr (next_arg))
79 [options, valid] = __pltopt__ (caller, next_arg, false);
82 error ("%s: properties must appear followed by a value", caller);
84 properties = [properties, [next_cell, varargin(k++)]];
88 while (nargs > 0 && ischar (varargin{k}))
90 error ("%s: properties must appear followed by a value",
93 properties = [properties, varargin(k:k+1)];
99 tmp = __plt2__ (h, x, y, options, properties);
100 [hlgnd, tlgnd, setlgnd] = __plt_key__ (tmp, options, hlgnd, tlgnd, setlgnd);
102 retval = [retval; tmp];
104 tmp = __plt1__ (h, x, options, properties);
105 [hlgnd, tlgnd, setlgnd] = __plt_key__ (tmp, options, hlgnd, tlgnd, setlgnd);
107 retval = [retval; tmp];
112 error ("plot: no data to plot");
116 options = __pltopt__ (caller, {""});
117 tmp = __plt2__ (h, x, y, options, properties);
118 [hlgnd, tlgnd, setlgnd] = __plt_key__ (tmp, options, hlgnd, tlgnd, setlgnd);
119 retval = [retval; tmp];
135 legend (gca(), hlgnd, tlgnd);
138 error ("__plt__: invalid number of arguments");
143 function [hlgnd, tlgnd, setlgnd] = __plt_key__ (h, options, hlgnd, tlgnd, setlgnd)
145 if (numel (options) == 1)
146 options = repmat (options(:), n, 1);
152 hlgnd = [hlgnd(:); h(i)];
153 tlgnd = {tlgnd{:}, key};
159 function retval = __plt1__ (h, x1, options, properties)
161 if (nargin < 2 || nargin > 4)
165 if (nargin < 3 || isempty (options))
166 options = __default_plot_options__ ();
173 if (! isstruct (options))
174 error ("__plt1__: options must be a struct array");
177 [nr, nc] = size (x1);
185 if (any (any (x1_i)))
193 retval = __plt2__ (h, x1, x2, options, properties);
197 function retval = __plt2__ (h, x1, x2, options, properties)
199 if (nargin < 3 || nargin > 5)
203 if (nargin < 4 || isempty (options))
204 options = __default_plot_options__ ();
211 if (! isstruct (options))
212 error ("__plt1__: options must be a struct array");
215 if (any (any (imag (x1))))
219 if (any (any (imag (x2))))
224 if (isempty (x1) && isempty (x2))
225 retval = zeros (0, 1);
226 elseif (isscalar (x1))
228 retval = __plt2ss__ (h, x1, x2, options, properties);
229 elseif (isvector (x2))
230 retval = __plt2sv__ (h, x1, x2, options, properties);
232 error ("__plt2__: invalid data for plotting");
234 elseif (isvector (x1))
236 retval = __plt2vs__ (h, x1, x2, options, properties);
237 elseif (isvector (x2))
238 retval = __plt2vv__ (h, x1, x2, options, properties);
239 elseif (ismatrix (x2))
240 retval = __plt2vm__ (h, x1, x2, options, properties);
242 error ("__plt2__: invalid data for plotting");
244 elseif (ismatrix (x1))
246 retval = __plt2mv__ (h, x1, x2, options, properties);
247 elseif (ismatrix (x2))
248 retval = __plt2mm__ (h, x1, x2, options, properties);
250 error ("__plt2__: invalid data for plotting");
253 error ("__plt2__: invalid data for plotting");
258 function retval = __plt2mm__ (h, x, y, options, properties)
260 if (nargin < 3 || nargin > 5)
264 if (nargin < 4 || isempty (options))
265 options = __default_plot_options__ ();
272 [x_nr, x_nc] = size (x);
273 [y_nr, y_nc] = size (y);
276 if (x_nr == y_nr && x_nc == y_nc)
278 if (numel (options) == 1)
279 options = repmat (options(:), x_nc, 1);
281 retval = zeros (x_nc, 1);
283 linestyle = options(i).linestyle;
284 marker = options(i).marker;
285 if (isempty (marker) && isempty (linestyle))
286 [linestyle, marker] = __next_line_style__ ();
288 color = options(i).color;
290 color = __next_line_color__ ();
293 retval(i) = line (x(:,i), y(:,i), "color", color,
294 "linestyle", linestyle,
295 "marker", marker, properties{:});
298 error ("__plt2mm__: arguments must be a matrices");
301 error ("__plt2mm__: matrix dimensions must match");
306 function retval = __plt2mv__ (h, x, y, options, properties)
308 if (nargin < 3 || nargin > 5)
312 if (nargin < 4 || isempty (options))
313 options = __default_plot_options__ ();
320 [x_nr, x_nc] = size (x);
321 [y_nr, y_nc] = size (y);
332 elseif (x_nc == y_nr)
338 error ("__plt2mv__: matrix dimensions must match");
342 if (numel (options) == 1)
343 options = repmat (options(:), x_nc, 1);
345 retval = zeros (x_nc, 1);
347 linestyle = options(i).linestyle;
348 marker = options(i).marker;
349 if (isempty (marker) && isempty (linestyle))
350 [linestyle, marker] = __next_line_style__ ();
352 color = options(i).color;
354 color = __next_line_color__ ();
357 retval(i) = line (x(:,i), y, "color", color,
358 "linestyle", linestyle,
359 "marker", marker, properties{:});
362 error ("__plt2mv__: arguments must be a matrices");
367 function retval = __plt2ss__ (h, x, y, options, properties)
369 if (nargin < 3 || nargin > 5)
373 if (nargin < 4 || isempty (options))
374 options = __default_plot_options__ ();
381 if (numel (options) > 1)
382 options = options(1);
385 [x_nr, x_nc] = size (x);
386 [y_nr, y_nc] = size (y);
388 if (x_nr == 1 && x_nr == y_nr && x_nc == 1 && x_nc == y_nc)
389 linestyle = options.linestyle;
390 marker = options.marker;
391 if (isempty (marker) && isempty (linestyle))
392 [linestyle, marker] = __next_line_style__ ();
394 color = options.color;
396 color = __next_line_color__ ();
399 retval = line (x, y, "color", color,
400 "linestyle", linestyle,
401 "marker", marker, properties{:});
403 error ("__plt2ss__: arguments must be scalars");
408 function retval = __plt2sv__ (h, x, y, options, properties)
410 if (nargin < 3 || nargin > 5)
414 if (nargin < 4 || isempty (options))
415 options = __default_plot_options__ ();
422 if (isscalar (x) && isvector (y))
424 if (numel (options) == 1)
425 options = repmat (options(:), len, 1);
427 retval = zeros (len, 1);
429 linestyle = options(i).linestyle;
430 marker = options(i).marker;
431 if (isempty (marker) && isempty (linestyle))
432 [linestyle, marker] = __next_line_style__ ();
434 color = options(i).color;
436 color = __next_line_color__ ();
439 retval(i) = line (x, y(i), "color", color,
440 "linestyle", linestyle,
441 "marker", marker, properties{:});
444 error ("__plt2sv__: first arg must be scalar, second arg must be vector");
449 function retval = __plt2vm__ (h, x, y, options, properties)
451 if (nargin < 3 || nargin > 5)
455 if (nargin < 4 || isempty (options))
456 options = __default_plot_options__ ();
463 [x_nr, x_nc] = size (x);
464 [y_nr, y_nc] = size (y);
475 elseif (x_nr == y_nc)
481 error ("__plt2vm__: matrix dimensions must match");
485 if (numel (options) == 1)
486 options = repmat (options(:), y_nc, 1);
488 retval = zeros (y_nc, 1);
490 linestyle = options(i).linestyle;
491 marker = options(i).marker;
492 if (isempty (marker) && isempty (linestyle))
493 [linestyle, marker] = __next_line_style__ ();
495 color = options(i).color;
497 color = __next_line_color__ ();
500 retval(i) = line (x, y(:,i), "color", color,
501 "linestyle", linestyle,
502 "marker", marker, properties{:});
505 error ("__plt2vm__: arguments must be a matrices");
510 function retval = __plt2vs__ (h, x, y, options, properties)
512 if (nargin < 3 || nargin > 5)
516 if (nargin < 4 || isempty (options))
517 options = __default_plot_options__ ();
524 if (isvector (x) && isscalar (y))
526 if (numel (options) == 1)
527 options = repmat (options(:), len, 1);
529 retval = zeros (len, 1);
531 linestyle = options(i).linestyle;
532 marker = options(i).marker;
533 if (isempty (marker) && isempty (linestyle))
534 [linestyle, marker] = __next_line_style__ ();
536 color = options(i).color;
538 color = __next_line_color__ ();
541 retval(i) = line (x(i), y, "color", color,
542 "linestyle", linestyle,
543 "marker", marker, properties{:});
546 error ("__plt2vs__: first arg must be vector, second arg must be scalar");
551 function retval = __plt2vv__ (h, x, y, options, properties)
553 if (nargin < 3 || nargin > 5)
557 if (nargin < 4 || isempty (options))
558 options = __default_plot_options__ ();
565 if (numel (options) > 1)
566 options = options(1);
569 [x_nr, x_nc] = size (x);
570 [y_nr, y_nc] = size (y);
587 linestyle = options.linestyle;
588 marker = options.marker;
589 if (isempty (marker) && isempty (linestyle))
590 [linestyle, marker] = __next_line_style__ ();
592 color = options.color;
594 color = __next_line_color__ ();
597 retval = line (x, y, "color", color,
598 "linestyle", linestyle,
599 "marker", marker, properties{:});
601 error ("__plt2vv__: vector lengths must match");