ColorBar ignore range with blank color

12 views (last 30 days)
sara_game7
sara_game7 on 6 Oct 2016
Commented: Anil Kumar on 10 Dec 2021
Hello!,
I have created one graph with colorbar ignoring certain range. I have replaced values in specified range for NAN values and automatically these values are displayed in blank, but not in the color bar. I would like to see the specified range in blank in the colorbar.
I have tried to modify the map matrix colors to [1 1 1] looking for the values considering nº of values and color bar limits, but is not working because I do not know how find the exactly position (rows) of the map matrix. The next code is not working with precision.
if threshold >0
threshold=1/(colourbar_limit/threshold);
min=round((length(map)/2)-((length(map)/2)*(threshold)));
max=round((length(map)/2)+((length(map)/2)*(threshold)));
for i=min:max
map(i,:) = [1 1 1]; % set that position to white (light green around zero)
end
else
end

Answers (1)

Marc Jakobi
Marc Jakobi on 7 Oct 2016
I had a similar problem once. I can't find the script I had the solution in, but what I did was set the NaNs to a number smaller than the smallest number in the data, e. g.
data(isnan(data)) = -1;
or
data(isnan(data)) = min(data{:)) - 1;
Then I defined my colormap by adding white at the beginning:
customcmap = [(1 1 1); jet]; %you can use any colormap instead of jet here
colormap(customcmap)
  3 Comments
Marc Jakobi
Marc Jakobi on 7 Oct 2016
Then I would change the values between -5 to 5 to -101 and then change the TickLabels of the colorbar
data(data >= -5 && data <= 5) = -101
cmap = [(1 1 1); jet];
colormap(cmap)
cbr = colorbar;
tl = get(cbr, 'TickLabels');
tl{1} = 'NaN' % blank range indicator as string
set(cbr, 'TickLabels', tl)
Anil Kumar
Anil Kumar on 10 Dec 2021
Dear Marc,
is it possible to fill colorbar with white sapace after
max(data1)
for the first plot (say), in order to make equal range for the colorbars axis of the two plots with
max(data2)>>max(data1)
Thanks...

Sign in to comment.

Categories

Find more on Colormaps in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!