annotate scripts/image/colormap.m @ 23083:e9a0469dedd9 stable

maint: strip extra trailing newlines from files.
author John W. Eaton <jwe@octave.org>
date Fri, 20 Jan 2017 12:19:08 -0500
parents c44d57c0a925
children ef4d915df748 3ac9f9ecfae5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22323
bac0d6f07a3e maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents: 21973
diff changeset
1 ## Copyright (C) 1994-2016 John W. Eaton
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
2 ## Copyright (C) 2012 Carnë Draug
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
9 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
15 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
18 ## <http://www.gnu.org/licenses/>.
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
19
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3373
diff changeset
20 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20532
diff changeset
21 ## @deftypefn {} {@var{cmap} =} colormap ()
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20532
diff changeset
22 ## @deftypefnx {} {@var{cmap} =} colormap (@var{map})
21973
894239974868 colormap: remove functionality to list and register colormaps (bug #48272)
Carnë Draug <carandraug@octave.org>
parents: 21758
diff changeset
23 ## @deftypefnx {} {@var{cmap} =} colormap (@qcode{"default"})
894239974868 colormap: remove functionality to list and register colormaps (bug #48272)
Carnë Draug <carandraug@octave.org>
parents: 21758
diff changeset
24 ## @deftypefnx {} {@var{cmap} =} colormap (@var{map_name})
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20532
diff changeset
25 ## @deftypefnx {} {@var{cmap} =} colormap (@var{hax}, @dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20532
diff changeset
26 ## @deftypefnx {} {} colormap @var{map_name}
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14246
diff changeset
27 ## Query or set the current colormap.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3381
diff changeset
28 ##
16946
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
29 ## With no input arguments, @code{colormap} returns the current color map.
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
30 ##
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3238
diff changeset
31 ## @code{colormap (@var{map})} sets the current colormap to @var{map}. The
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14246
diff changeset
32 ## colormap should be an @var{n} row by 3 column matrix. The columns
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3238
diff changeset
33 ## contain red, green, and blue intensities respectively. All entries
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14246
diff changeset
34 ## must be between 0 and 1 inclusive. The new colormap is returned.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3381
diff changeset
35 ##
21973
894239974868 colormap: remove functionality to list and register colormaps (bug #48272)
Carnë Draug <carandraug@octave.org>
parents: 21758
diff changeset
36 ## @code{colormap (@qcode{"default"})} restores the default colormap (the
20532
2480bbcd1333 fix documentation for new viridis colormap
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
37 ## @code{viridis} map with 64 entries). The default colormap is returned.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3381
diff changeset
38 ##
21973
894239974868 colormap: remove functionality to list and register colormaps (bug #48272)
Carnë Draug <carandraug@octave.org>
parents: 21758
diff changeset
39 ## The map may also be specified by a string, @var{map_name}, which
894239974868 colormap: remove functionality to list and register colormaps (bug #48272)
Carnë Draug <carandraug@octave.org>
parents: 21758
diff changeset
40 ## is the name of a function that returns a colormap.
17305
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
41 ##
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
42 ## If the first argument @var{hax} is an axes handle, then the colormap for
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
43 ## the parent figure of @var{hax} is queried or set.
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
44 ##
16947
24bb7dc754ed Document command form of colormap().
Carnë Draug <carandraug@octave.org>
parents: 16946
diff changeset
45 ## For convenience, it is also possible to use this function with the
17305
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
46 ## command form, @code{colormap @var{map_name}}.
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
47 ##
22628
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
48 ## The list of built-in colormaps is:
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
49 ##
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
50 ## @c FIXME: It would be nice to display the actual colormap as an image
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
51 ## @c in the PDF version of the documentation.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
52 ## @multitable @columnfractions 0.15 .85
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
53 ## @headitem Map @tab Description
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
54 ## @item viridis @tab default
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
55 ## @item jet @tab colormap traversing blue, cyan, green, yellow, red.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
56 ## @item cubehelix @tab colormap traversing black, blue, green, red, white with increasing intensity.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
57 ## @item hsv @tab cyclic colormap traversing Hue, Saturation, Value space.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
58 ## @item rainbow @tab colormap traversing red, yellow, blue, green, violet.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
59 ## @item ------------- @tab ---------------------------------------------------------------------------------------------
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
60 ## @item hot @tab colormap traversing black, red, orange, yellow, white.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
61 ## @item cool @tab colormap traversing cyan, purple, magenta.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
62 ## @item spring @tab colormap traversing magenta to yellow.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
63 ## @item summer @tab colormap traversing green to yellow.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
64 ## @item autumn @tab colormap traversing red, orange, yellow.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
65 ## @item winter @tab colormap traversing blue to green.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
66 ## @item ------------- @tab ---------------------------------------------------------------------------------------------
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
67 ## @item gray @tab colormap traversing black to white in shades of gray.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
68 ## @item bone @tab colormap traversing black, gray-blue, white.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
69 ## @item copper @tab colormap traversing black to light copper.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
70 ## @item pink @tab colormap traversing black, gray-pink, white.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
71 ## @item ocean @tab colormap traversing black, dark-blue, white.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
72 ## @item ------------- @tab ---------------------------------------------------------------------------------------------
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
73 ## @item colorcube @tab equally spaced colors in RGB color space.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
74 ## @item flag @tab cyclic 4-color map of red, white, blue, black.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
75 ## @item lines @tab cyclic colormap with colors from axes @qcode{"ColorOrder"} property.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
76 ## @item prism @tab cyclic 6-color map of red, orange, yellow, green, blue, violet.
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
77 ## @item ------------- @tab ---------------------------------------------------------------------------------------------
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
78 ## @item white @tab all white colormap (no colors).
22636
c44d57c0a925 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22628
diff changeset
79 ## @end multitable
22628
a918e983a943 doc: Add list of built-in colormaps to colormap documentation (bug #49363).
Rik <rik@octave.org>
parents: 22543
diff changeset
80 ## @seealso{viridis, jet, cubehelix, hsv, rainbow, hot, cool, spring, summer, autumn, winter, gray, bone, copper, pink, ocean, colorcube, flag, lines, prism, white}
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3238
diff changeset
81 ## @end deftypefn
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
82
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3106
diff changeset
83 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
84 ## Created: July 1994
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
85 ## Adapted-By: jwe
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 559
diff changeset
86
17305
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
87 function cmap = colormap (varargin)
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 20852
diff changeset
88
17305
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
89 [hax, varargin, nargin] = __plt_get_axis_arg__ ("colormap", varargin{:});
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
90
21973
894239974868 colormap: remove functionality to list and register colormaps (bug #48272)
Carnë Draug <carandraug@octave.org>
parents: 21758
diff changeset
91 if (nargin > 1)
5923
611e30b984b3 [project @ 2006-08-14 18:29:18 by jwe]
jwe
parents: 5443
diff changeset
92 print_usage ();
1062
1b3a87031641 [project @ 1995-01-24 02:54:50 by jwe]
jwe
parents: 1024
diff changeset
93 endif
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
94
17305
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
95 if (! isempty (hax))
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
96 cf = ancestor (hax, "figure");
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
97 else
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
98 cf = get (0, "currentfigure");
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
99 endif
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
100
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
101 if (nargin == 1)
17305
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
102 map = varargin{1};
5443
ec8c33dcd1bf [project @ 2005-09-08 01:40:57 by jwe]
jwe
parents: 5307
diff changeset
103 if (ischar (map))
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
104 if (strcmp (map, "default"))
20532
2480bbcd1333 fix documentation for new viridis colormap
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
105 map = viridis (64);
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
106 else
22543
b9f5ac691e03 colormap.m: Emit clearer error when map name does not exist (bug #49202).
Rik <rik@octave.org>
parents: 22323
diff changeset
107 try
b9f5ac691e03 colormap.m: Emit clearer error when map name does not exist (bug #49202).
Rik <rik@octave.org>
parents: 22323
diff changeset
108 map = feval (map);
b9f5ac691e03 colormap.m: Emit clearer error when map name does not exist (bug #49202).
Rik <rik@octave.org>
parents: 22323
diff changeset
109 catch
b9f5ac691e03 colormap.m: Emit clearer error when map name does not exist (bug #49202).
Rik <rik@octave.org>
parents: 22323
diff changeset
110 error ("colormap: failed to set MAP <%s>", map);
b9f5ac691e03 colormap.m: Emit clearer error when map name does not exist (bug #49202).
Rik <rik@octave.org>
parents: 22323
diff changeset
111 end_try_catch
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
112 endif
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
113 endif
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
114
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
115 if (! isempty (map))
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
116 if (! (isnumeric (map) && isreal (map)
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
117 && ndims (map) == 2 && columns (map) == 3))
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
118 error ("colormap: MAP must be a real-valued N x 3 ([R,G,B]) matrix");
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
119 endif
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
120 if (any (map(:) < 0) || any (map(:) > 1))
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
121 error ("colormap: all MAP values must be in the range [0,1]");
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
122 endif
17305
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
123 if (isempty (cf))
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
124 cf = gcf ();
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
125 endif
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1887
diff changeset
126 ## Set the new color map
17305
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
127 set (cf, "colormap", map);
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
128 endif
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
129 endif
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
130
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1887
diff changeset
131 ## Return current color map.
21973
894239974868 colormap: remove functionality to list and register colormaps (bug #48272)
Carnë Draug <carandraug@octave.org>
parents: 21758
diff changeset
132 if (nargout > 0 || nargin == 0)
17305
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
133 if (isempty (cf))
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
134 cf = gcf ();
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
135 endif
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
136 cmap = get (cf, "colormap");
6762
721953d49b19 [project @ 2007-06-27 18:20:19 by jwe]
jwe
parents: 6257
diff changeset
137 endif
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
138
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
139 endfunction
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
140
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
141
16946
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
142 %!demo
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
143 %! ## Create an image for displaying a colormap
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
144 %! image (1:64, linspace (0, 1, 64), repmat ((1:64)', 1, 64));
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
145 %! axis ([1, 64, 0, 1], "ticy", "xy");
20532
2480bbcd1333 fix documentation for new viridis colormap
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
146 %! ## Show 'viridis' colormap
2480bbcd1333 fix documentation for new viridis colormap
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
147 %! colormap (viridis (64));
2480bbcd1333 fix documentation for new viridis colormap
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
148 %! title "colormap (viridis (64))"
16946
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
149 %! disp ("Press a key to continue");
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
150 %! pause ();
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
151 %! ## Show 'colorcube' colormap
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
152 %! colormap (colorcube (64));
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
153 %! title "colormap (colorcube (64))"
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
154
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
155 %!test
17305
ab71b9829752 colormap.m: Support axis handle as first argument.
Rik <rik@octave.org>
parents: 17281
diff changeset
156 %! hf = figure ("visible", "off");
19667
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
157 %! unwind_protect
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
158 %! cmaptst = [0 1 0; 1 0 1; 1 1 1];
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
159 %! cmap = colormap (cmaptst);
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
160 %! assert (cmap, cmaptst);
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
161 %! cmap = colormap ();
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
162 %! assert (cmap, cmaptst);
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
163 %! cmap = (get (gcf, "colormap"));
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
164 %! assert (cmap, cmaptst);
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
165 %! colormap ("default");
20532
2480bbcd1333 fix documentation for new viridis colormap
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
166 %! assert (colormap (), viridis (64));
19667
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
167 %! colormap ("ocean");
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
168 %! assert (colormap, ocean (64));
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
169 %! unwind_protect_cleanup
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
170 %! close (hf);
4b1a43786489 colormap.m: Don't show a figure during 'make check'
Mike Miller <mtmiller@ieee.org>
parents: 19610
diff changeset
171 %! end_unwind_protect
16946
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
172
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
173 ## Test input validation
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
174 %!error colormap (1,2,3)
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
175 %!error <MAP must be a real-valued N x 3> colormap ({1,2,3})
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
176 %!error <MAP must be a real-valued N x 3> colormap ([1 i 1])
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
177 %!error <MAP must be a real-valued N x 3> colormap (ones(3,3,3))
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
178 %!error <MAP must be a real-valued N x 3> colormap ([1 0 1 0])
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
179 %!error <all MAP values must be in the range> colormap ([-1 0 0])
92f42d9f2ae4 colormap.m: Add demos, tests, and warning when using deprecated syntax.
Rik <rik@octave.org>
parents: 16766
diff changeset
180 %!error <all MAP values must be in the range> colormap ([2 0 0])
22543
b9f5ac691e03 colormap.m: Emit clearer error when map name does not exist (bug #49202).
Rik <rik@octave.org>
parents: 22323
diff changeset
181 %!error <failed to set MAP .invalid_map_name.> colormap ("invalid_map_name")