See https://www.mathworks.com/matlabcentral/fileexchange/69470-custom-colormap
The function expects positions in the range 0 to 1, so you will need to rescale() your valid key values from whatever fixed range they have now to the [0 1] range.It looks like you might have the range -1 to +1 so add 1 to the key values and divide the result by 2 to get the [0 1] position for the purposes of the function.
Then when you colormap() the new map into place, be sure the caxis([-1 1]) or as appropriate the fixed values.
Each "slot" in a colormap is exactly the same size: for a colormap with N rows, each entry in the colormap covers 1/N of the defined range of values. It is not possible to say that 0.2 to 0.4 is a single slot that is one color but that other slots are to be different widths. If you want different colors in the map to represent different data spans, then what you have to do is use more rows in the colormap but repeat individual colors. For example if you had one color of desired width 0.2 and another of desired width 0.18 then you could use enough rows that an individual slot covered 0.02 of the range, and the 0.2 repeated a color 10 times and the 0.18 repeated it color 9 times. You cannot just create a colormap with arbitrary breakspoints, colormap processing is always a linear mapping process. Answer from Walter Roberson on mathworks.com
MathWorks
mathworks.com › matlab › graphics › labels and styling › color and styling
Control Colormap Limits - MATLAB & Simulink
For many types of visualizations you create, MATLAB® maps the full range of your data to the colormap by default. The smallest value in your data maps to the first row in the colormap, and the largest value maps to the last row in the colormap.
MathWorks
mathworks.com › matlab › graphics › labels and styling › color and styling
colormap - View and set current colormap - MATLAB
An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities can be double or single values in the range [0, 1], or they can be uint8 values in the range [0, 255]. For example, this matrix defines a ...
Videos
MathWorks
mathworks.com › matlab › graphics › labels and styling › color and styling
clim - Set colormap limits (Renamed from caxis in R2022a) - MATLAB
Set the colormap limits for multiple axes or charts at once by specifying the target argument as an array of axes or standalone visualizations. To align the function name with the CLim axes property, caxis is now called clim. ... Run the command by entering it in the MATLAB Command Window.
MathWorks
mathworks.com › matlabcentral › answers › 422753-how-to-set-a-value-range-for-predefined-colormap
How to set a value range for predefined colormap? - MATLAB Answers - MATLAB Central
October 8, 2018 - I would like to set like 0 is the lowest value (in 'winter' blue) and 20 (in 'winter' yellow) the highest. If one of the plots show maximum values of 5 there shouldn't be any yellow color.
MathWorks
mathworks.com › matlab › graphics › labels and styling › color and styling
Change Color Scheme Using a Colormap - MATLAB & Simulink
You can also create your own colormap as an m-by-3 array. Each row in the array contains the red, green, and blue intensities of a different color. The intensities are in the range [0,1]. Here is a simple colormap that contains three entries.
MathWorks
mathworks.com › matlabcentral › answers › 289537-how-define-colormap-for-range-of-value-of-z-data
how define colormap for range of value of z data - MATLAB Answers - MATLAB Central
June 13, 2016 - i want create colormap for z value by following range : 100-1200 blue 1200-1300 red 1300-1400 yellow 1400 to up green, please help me to create this colormap. thanks. Sign in to comment.
MathWorks
mathworks.com › matlab › graphics › labels and styling › color and styling
How Image Data Relates to a Colormap - MATLAB & Simulink
When you display images using the image function, you can control how the range of pixel values maps to the range of the colormap. For example, here is a 5-by-5 magic square displayed as an image using the default colormap. ... A contains values between 1 and 25. MATLAB® treats those values ...
Top answer 1 of 3
11
I believe that caxis is the command you're looking for. Usage:
caxis([minValue maxValue])
Using caxis like this, all values outside the range [minValue maxValue] will be coloured with the lowest or highest value in the colormap, respectively.
Since colorbar and friends use colormap, you'll have to adjust the current colormap if you want to adjust the number of colors used. Do this like so:
%# get current colormap
map = colormap;
%# adjust for number of colors you want
rows = uint16(linspace(1, size(map,1), NUM_COLORS)) ;
map = map(rows, :);
%# and apply the new colormap
colormap(map);
Of course, combining this with caxis is the most powerful.
If you don't want to show some values outside of range, that's not a job for colorbar or caxis, that's up to you -- you'll have to adjust the data that's plotted so that all values you don't want plotted are NaN. Doing so will make Matlab understand that you don't want to plot these data:
data( indices_to_data_not_to_plot ) = NaN;
surf(x,y,data); %# or whatever you're using
2 of 3
0
How about this?
% don’t know why, but apparently your x and y are one value too long?
x = x(1:end-1); y = y(1:end-1);
% only plot values of 14 or higher
scatter(x(gnd>=14), y(gnd>=14), 5, gnd(gnd>=14);
MathWorks
mathworks.com › matlabcentral › answers › 248210-how-to-set-colorbar-limits
How to set colorbar limits? - MATLAB Answers - MATLAB Central
October 12, 2015 - If you want to define the colormap to have fewer colours that the default (or a certain specific set of colours), you just have to tell it. See the documentation for colormap for details. The colormap itself is a (Nx3) matrix. (Please do not use min and max as variable names. They are built-in MATLAB functions, and will cause problems if you want to use the functions later in your code.)
MathWorks
mathworks.com › matlabcentral › answers › 542924-how-to-scale-the-range-of-a-custom-colormap-correctly
How to scale the range of a custom colormap correctly? - MATLAB Answers - MATLAB Central
June 5, 2020 - I have successfully scaled the colormap limits of the axes to the one that I wanted. Glad and thankyou for the answer. ... https://www.mathworks.com/matlabcentral/answers/542924-how-to-scale-the-range-of-a-custom-colormap-correctly#comment_886595
MathWorks
mathworks.com › matlab › graphics › images
imagesc - Display image with scaled colors - MATLAB
Create matrix C. Display an image ... limits so that image uses the full range of the colormap, where the smallest value in C maps to the first color in the colormap and the largest value maps to the last color....




