7017
|
1 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2003, 2005, |
|
2 ## 2006, 2007 John W. Eaton |
2313
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
7016
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
2313
|
10 ## |
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
1024
|
19 |
3381
|
20 ## -*- texinfo -*- |
3373
|
21 ## @deftypefn {Function File} {} colormap (@var{map}) |
|
22 ## @deftypefnx {Function File} {} colormap ("default") |
2311
|
23 ## Set the current colormap. |
3426
|
24 ## |
3373
|
25 ## @code{colormap (@var{map})} sets the current colormap to @var{map}. The |
|
26 ## color map should be an @var{n} row by 3 column matrix. The columns |
|
27 ## contain red, green, and blue intensities respectively. All entries |
|
28 ## should be between 0 and 1 inclusive. The new colormap is returned. |
3426
|
29 ## |
6895
|
30 ## @code{colormap ("default")} restores the default colormap (the |
|
31 ## @code{jet} map with 64 entries). The default colormap is returned. |
3426
|
32 ## |
3373
|
33 ## With no arguments, @code{colormap} returns the current color map. |
6895
|
34 ## @seealso{jet} |
3373
|
35 ## @end deftypefn |
559
|
36 |
3202
|
37 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
38 ## Created: July 1994 |
|
39 ## Adapted-By: jwe |
904
|
40 |
6762
|
41 ## PKG_ADD: mark_as_command colormap |
|
42 |
2312
|
43 function cmap = colormap (map) |
559
|
44 |
1062
|
45 if (nargin > 1) |
5923
|
46 print_usage (); |
1062
|
47 endif |
559
|
48 |
1024
|
49 if (nargin == 1) |
3238
|
50 |
5443
|
51 if (ischar (map)) |
1024
|
52 if (strcmp (map, "default")) |
6895
|
53 map = jet (64); |
559
|
54 else |
6257
|
55 map = feval (map); |
559
|
56 endif |
3238
|
57 endif |
|
58 |
|
59 if (! isempty (map)) |
|
60 if (columns (map) != 3) |
3458
|
61 error ("colormap: map must have 3 columns: [R,G,B]"); |
3238
|
62 endif |
|
63 if (min (min (map)) < 0 || max (max (map)) > 1) |
3458
|
64 error ("colormap: map must have values in [0,1]"); |
3238
|
65 endif |
2303
|
66 ## Set the new color map |
6257
|
67 set (gcf (), "colormap", map); |
559
|
68 endif |
3238
|
69 |
559
|
70 endif |
|
71 |
2303
|
72 ## Return current color map. |
7108
|
73 if (nargout > 0 || (nargout == 0 && nargin == 0)) |
6762
|
74 cmap = get (gcf (), "colormap"); |
|
75 endif |
1024
|
76 |
559
|
77 endfunction |