time | Calls | line |
---|
| | 1 | function map = colormap(arg1,arg2)
|
| | 2 | %COLORMAP Color look-up table.
|
| | 3 | % COLORMAP(MAP) sets the current figure's colormap to MAP.
|
| | 4 | % COLORMAP('default') sets the current figure's colormap to
|
| | 5 | % the root's default, whose setting is PARULA.
|
| | 6 | % MAP = COLORMAP returns the three-column matrix of RGB triplets defining
|
| | 7 | % the colormap for the current figure.
|
| | 8 | % COLORMAP(FIG,...) sets the colormap for the figure specified by FIG.
|
| | 9 | % COLORMAP(AX,...) sets the colormap for the axes specified by AX.
|
| | 10 | % Each axes within a figure can have a unique colormap. After you set
|
| | 11 | % an axes colormap, changing the figure colormap does not affect the axes.
|
| | 12 | % MAP = COLORMAP(FIG) returns the colormap for the figure specified by FIG.
|
| | 13 | % MAP = COLORMAP(AX) returns the colormap for the axes specified by AX.
|
| | 14 | %
|
| | 15 | % A color map matrix may have any number of rows, but it must have
|
| | 16 | % exactly 3 columns. Each row is interpreted as a color, with the
|
| | 17 | % first element specifying the intensity of red light, the second
|
| | 18 | % green, and the third blue. Color intensity can be specified on the
|
| | 19 | % interval 0.0 to 1.0.
|
| | 20 | % For example, [0 0 0] is black, [1 1 1] is white,
|
| | 21 | % [1 0 0] is pure red, [.5 .5 .5] is gray, and
|
| | 22 | % [127/255 1 212/255] is aquamarine.
|
| | 23 | %
|
| | 24 | % Graphics objects that use pseudocolor -- SURFACE and PATCH objects,
|
| | 25 | % which are created by the functions MESH, SURF, and PCOLOR -- map
|
| | 26 | % a color matrix, C, whose values are in the range [Cmin, Cmax],
|
| | 27 | % to an array of indices, k, in the range [1, m].
|
| | 28 | % The values of Cmin and Cmax are either min(min(C)) and max(max(C)),
|
| | 29 | % or are specified by CAXIS. The mapping is linear, with Cmin
|
| | 30 | % mapping to index 1 and Cmax mapping to index m. The indices are
|
| | 31 | % then used with the colormap to determine the color associated
|
| | 32 | % with each matrix element. See CAXIS for details.
|
| | 33 | %
|
| | 34 | % Type HELP GRAPH3D to see a number of useful colormaps.
|
| | 35 | %
|
| | 36 | % COLORMAP is a function that sets the Colormap property of a figure.
|
| | 37 | %
|
| | 38 | % See also HSV, CAXIS, SPINMAP, BRIGHTEN, RGBPLOT, FIGURE, COLORMAPEDITOR.
|
| | 39 |
|
| | 40 | % Copyright 1984-2017 The MathWorks, Inc.
|
| | 41 |
|
| | 42 | import matlab.graphics.internal.*;
|
< 0.001 | 2 | 43 | arg = 0;
|
< 0.001 | 2 | 44 | if (nargin == 0)
|
| | 45 | figH = gcf;
|
0.001 | 2 | 46 | elseif (isCharOrString(arg1))||(length(arg1) > 1)||isempty(arg1)
|
| | 47 | % string input (check for valid option later)
|
< 0.001 | 2 | 48 | if (nargin == 2)
|
| | 49 | error(message('MATLAB:colormap:InvalidFirstArgument'));
|
< 0.001 | 2 | 50 | end
|
< 0.001 | 2 | 51 | figH = gcf;
|
< 0.001 | 2 | 52 | if (isCharOrString(arg1))
|
| | 53 | arg = lower(arg1);
|
< 0.001 | 2 | 54 | else
|
< 0.001 | 2 | 55 | arg = arg1;
|
< 0.001 | 2 | 56 | end
|
| | 57 | else
|
| | 58 | % figH can be any object that can contain a colormap
|
| | 59 | figH = getMapContainer(arg1);
|
| | 60 | if isempty(figH)
|
| | 61 | error(message('MATLAB:colormap:NeedScalarHandle'));
|
| | 62 | end
|
| | 63 |
|
| | 64 | % check for string option
|
| | 65 | if nargin == 2
|
| | 66 | if (isCharOrString(arg2))
|
| | 67 | arg = lower(arg2);
|
| | 68 | else
|
| | 69 | arg = arg2;
|
| | 70 | end
|
| | 71 | end
|
< 0.001 | 2 | 72 | end
|
| | 73 |
|
< 0.001 | 2 | 74 | if isequal(arg,0)
|
| | 75 | map = get(figH, 'Colormap');
|
| | 76 | return
|
< 0.001 | 2 | 77 | end
|
< 0.001 | 2 | 78 | if isCharOrString(arg)
|
| | 79 | % For indexing purpose, convert arg to char.
|
| | 80 | arg = char(arg);
|
| | 81 | if strcmp(arg,'default')
|
| | 82 | fig = ancestor(figH,'figure');
|
| | 83 | defaultMap = get(fig,'defaultfigureColormap');
|
| | 84 | set(figH,'Colormap',defaultMap);
|
| | 85 | return;
|
| | 86 | end
|
| | 87 | k = min(strfind(arg,'('));
|
| | 88 | if ~isempty(k)
|
| | 89 | arg = feval(arg(1:k-1),str2double(arg(k+1:end-1)));
|
| | 90 | else
|
| | 91 | arg = feval(arg);
|
| | 92 | end
|
< 0.001 | 2 | 93 | end
|
< 0.001 | 2 | 94 | if ~isempty(arg)
|
< 0.001 | 2 | 95 | if (size(arg,2) ~= 3)
|
| | 96 | error(message('MATLAB:colormap:InvalidNumberColumns'));
|
< 0.001 | 2 | 97 | end
|
0.001 | 2 | 98 | if min(min(arg)) < 0 || max(max(arg)) > 1
|
| | 99 | error(message('MATLAB:colormap:InvalidInputRange'))
|
< 0.001 | 2 | 100 | end
|
< 0.001 | 2 | 101 | end
|
0.001 | 2 | 102 | set(figH, 'Colormap', arg);
|
< 0.001 | 2 | 103 | if nargout == 1
|
| | 104 | map = get(figH, 'Colormap');
|
< 0.001 | 2 | 105 | end
|
< 0.001 | 2 | 106 | end
|