ColorBar ignore range with blank color

10 次查看(过去 30 天)
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

回答(1 个)

Marc Jakobi
Marc Jakobi 2016-10-7
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 个评论
Marc Jakobi
Marc Jakobi 2016-10-7
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 2021-12-10
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...

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by