Custom colormap for a contourf plot?

조회 수: 6 (최근 30일)
Victor Kolobov
Victor Kolobov 2019년 7월 26일
답변: Ganesh Regoti 2019년 8월 2일
I am working on a contourf plot and my Z matrix contains heights between -2 and 2e+15 and the entries for which Z is undefined contain (-3).
1. I want a custom colormap for the Z filled contours such that:
The (-3) value contours will be colored in white.
The contours in the range (-2,0] will be colored in different shades of black linearly dependent on the heights.
The contours in the range [0,2) will be colored in different shades of magenta linearly dependent on the heights.
The contours in the range [2,10) will be colored in different shades of blue linearly dependent on the heights.
[10,1e+2) :different shades of cyan linearly dependent on the heights.
[1e+2,1e+4) :different shades of green linearly dependent on the heights.
[1e+4,1e+8) :different shades of yellow linearly dependent on the heights.
[1e+8,1e+16) :different shades of red linearly dependent on the heights.
.
2. I want a custom colorbar with all the ranges boundaries (and only them) mentioned on it and with different areas allocated to each range to illustrate their different magnitudes.
3. Only if possible: to allocate a small area to the white color at the bottom of this colorbar and instead of (-3), to write there: 'outside of the function domain'.
  댓글 수: 1
dpb
dpb 2019년 7월 27일
On a linear scale with values from ~0 to 10^15, only the top of the axis values will be anything visually but a plane at the origin.

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

답변 (1개)

Ganesh Regoti
Ganesh Regoti 2019년 8월 2일
See the following code which may help you
%% Colorbar ranges
crange = [-3 -2; -2 0; 0 2; 2 10; 10 100;100 10^4;10^4 10^8; 10^8 10^16];
cmap = rand(size(crange,1),3); %Specify your customized colors in RGB format
%% Data
[X, Y] = meshgrid(linspace(1,2^15,1000),linspace(0,2^15,1000));
A = X + Y; % I have used random data set.
%% Arrange the colors range
colors = zeros(size(A));
for i = 1:size(crange,1) % Categorizing the values which fall into specified range
colors(A > crange(i,1) & A<=crange(i,2)) = crange(i,2);
end
contourf(X,Y,colors,8);
%% Color bar
h = colorbar;
h.Ticks = -3:((10^8 +3)/8):10^8; % Set ticks for all ranges.
h.TickLabels = {'outside of function domain','-2','0','2','10','100','10^4','10^8','10^16'}; % Set tick labels.
caxis([-3 10^8]); % Set colormap limits
colormap(cmap);

카테고리

Help CenterFile Exchange에서 Color and Styling에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by