changelog shortlog tags changeset files revisions annotate raw

scripts/plot/ribbon.m

changeset 10289: 4b124317dc38
parent:dbd0c77e575e
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (58 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 2007, 2008, 2009 Kai Habel
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} {} ribbon (@var{x}, @var{y}, @var{width})
21## @deftypefnx {Function File} {} ribbon (@var{y})
22## @deftypefnx {Function File} {@var{h} =} ribbon (@dots{})
23## Plot a ribbon plot for the columns of @var{y} vs. @var{x}. The
24## optional parameter @var{width} specifies the width of a single ribbon
25## (default is 0.75). If @var{x} is omitted, a vector containing the
26## row numbers is assumed (1:rows(Y)). If requested, return a vector
27## @var{h} of the handles to the surface objects.
28## @seealso{gca, colorbar}
29## @end deftypefn
30
31## Author: Kai Habel <kai.habel at gmx.de>
32
33function h = ribbon (x, y, width)
34
35 newplot ();
36
37 if (nargin == 1)
38 y = x;
39 if (isvector (y))
40 y = y(:);
41 endif
42 [nr, nc] = size (y);
43 x = repmat ((1:nr)', 1, nc);
44 width = 0.75;
45 elseif (nargin == 2)
46 width = 0.75;
47 elseif (nargin != 3)
48 print_usage ();
49 endif
50
51 if (isvector (x) && isvector (y))
52 if (length (x) != length (y))
53 error ("ribbon: in case of vectors, X and Y must have same length");
54 else
55 [x, y] = meshgrid (x, y);
56 endif
57 else
58 if (! size_equal(x, y))
59 error ("ribbon: in case of matrices, X and Y must have same size");
60 endif
61 endif
62
63 [nr, nc] = size (y);
64 tmp = zeros (1, nc);
65
66 for c = nc:-1:1
67 zz = [y(:,c), y(:,c)];
68 yy = x(:,c);
69 xx = [c - width / 2, c + width / 2];
70 [xx, yy] = meshgrid (xx, yy);
71 cc = ones (size (zz)) * c;
72 tmp(c) = surface (xx, yy, zz, cc);
73 endfor
74
75 ax = get (tmp(c), "parent");
76
77 if (! ishold ())
78 set (ax, "view", [-37.5, 30], "box", "off", "xgrid", "on",
79 "ygrid", "on", "zgrid", "on");
80 endif
81
82 if (nargout > 0)
83 h = tmp;
84 endif
85
86endfunction
87
88%!demo
89%! [x, y, z] = sombrero ();
90%! [x, y] = meshgrid (x, y);
91%! ribbon (y, z);