]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/pcolor.m
update packages
[CreaPhase.git] / octave_packages / m / plot / pcolor.m
1 ## Copyright (C) 2007-2012 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} {} pcolor (@var{x}, @var{y}, @var{c})
21 ## @deftypefnx {Function File} {} pcolor (@var{c})
22 ## Density plot for given matrices @var{x}, and @var{y} from @code{meshgrid} and
23 ## a matrix @var{c} corresponding to the @var{x} and @var{y} coordinates of
24 ## the mesh's vertices.  If @var{x} and @var{y} are vectors, then a typical
25 ## vertex
26 ## is (@var{x}(j), @var{y}(i), @var{c}(i,j)).  Thus, columns of @var{c}
27 ## correspond to different @var{x} values and rows of @var{c} correspond
28 ## to different @var{y} values.
29 ##
30 ## The @code{colormap} is scaled to the extents of @var{c}.
31 ## Limits may be placed on the color axis by the
32 ## command @code{caxis}, or by setting the @code{clim} property of the
33 ## parent axis.
34 ##
35 ## The face color of each cell of the mesh is determined by interpolating
36 ## the values of @var{c} for the cell's vertices.  Contrast this with
37 ## @code{imagesc} which renders one cell for each element of @var{c}.
38 ##
39 ## @code{shading} modifies an attribute determining the manner by which the
40 ## face color of each cell is interpolated from the values of @var{c},
41 ## and the visibility of the cells' edges.  By default the attribute is
42 ## "faceted", which renders a single color for each cell's face with the edge
43 ## visible.
44 ##
45 ## @var{h} is the handle to the surface object.
46 ##
47 ## @seealso{caxis, contour, meshgrid, imagesc, shading}
48 ## @end deftypefn
49
50 ## Author: Kai Habel <kai.habel@gmx.de>
51
52 function h = pcolor (x, y, c)
53
54   newplot ();
55
56   if (nargin == 1)
57     c = x;
58     [nr, nc] = size(c);
59     z = zeros (nr, nc);
60     [x, y] = meshgrid (1:nc, 1:nr);
61   elseif (nargin == 3)
62     z = zeros (size (c));
63   else
64     print_usage ();
65   endif
66
67   tmp = surface (x, y, z, c);
68
69   ax = get (tmp, "parent");
70
71   set (tmp, "facecolor", "flat");
72   set (ax, "box", "on");
73
74   if (! ishold ())
75     set (ax, "view", [0, 90]);
76   endif
77
78   if (nargout > 0)
79     h = tmp;
80   endif
81
82 endfunction
83
84 %!demo
85 %! clf
86 %! [~,~,Z]=peaks;
87 %! pcolor(Z);
88
89 %!demo
90 %! clf
91 %! [X,Y,Z]=sombrero;
92 %! [Fx,Fy] = gradient(Z);
93 %! pcolor(X,Y,Fx+Fy);
94 %! shading interp;