필터 지우기
필터 지우기

Manual division of the colorbar

조회 수: 9 (최근 30일)
Eylon Vakrat
Eylon Vakrat 2023년 1월 7일
답변: Nehemiae 2023년 3월 8일
Hello everyone,
I'm trying to have a colorbar with only the value 0 will be in a specific grey. all values above, even slightly, will be in a different color, and I want the colorbar to be descrete, meaning 5-10 will have certain color, and not every number will have a different color.
This is the colorbar I have:
And this is the colorbar I want (but prettier ;) ):
Is there any way to do that?
Thank you in advance.
  댓글 수: 4
Rik
Rik 2023년 1월 8일
What exactly did you try? I don't recognize the interface, so I don't know how to most easily extract the colormap from this point.
Stephen23
Stephen23 2023년 1월 8일
"I don't recognize the interface..."
It is a recent version of the inbuilt COLORMAPEDITOR()

댓글을 달려면 로그인하십시오.

답변 (1개)

Nehemiae
Nehemiae 2023년 3월 8일
Hello,
It is possible to create a colormap with colours specified over ranges of inputs, and then input values within the specified ranges are scaled accordingly. This is shown in the case 1 of the code below. Based on the resolution chosen – a small set of values around 0, will be grey. In the second case, based on the kind of plot required (here heatmap was used), it is possible to set the input values with 0 to NaN, and display them in a separate colour using the “MissingDataColor” property.
colors = [255 0 0; 255 140 0; 255 255 0; 0 255 0; 0 0 255; 75 0 130] / 255; % Colors to be used in the colormap
c_levels = [0 5 10 15 20 25 30]; % Levels at which the color changes:
level_res = 0.001; % Resolution of each level
n_colors = round(diff(c_levels) / level_res); % Total number of colors in the map
% Create the colormap
cmap = [];
for i = 1 : numel(n_colors)
cmap = [cmap; repmat(colors(i, :), n_colors(i), 1)];
end
% Case 1: Grey color over a range
cmap1 = cmap;
cmap1(1, :) = [105 105 105] / 255; % Change the color of value 0 to required grey
data = [0; 0.000000001; 0.001; 0.01; 0.1; 1; 5; 10; 15; 20; 25];
figure;
h = heatmap(data);
h.Colormap = cmap1;
caxis([0 30]);
% Case 2: Only zero set to grey in heatmap
cmap2 = cmap;
data(data == 0) = NaN;
figure;
h = heatmap(data);
h.Colormap = cmap2;
h.MissingDataColor = [105 105 105] / 255;
caxis([0 30]);
The documentation on HeatmapChart properties (https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.heatmapchart-properties.html) can be helpful in understanding the above code.

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by