How to obtain a cutsomized colorbar at certain color value range?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi,
I would like to obtain a customizd colorbar that has a range from 0-24.
I would like to paint black color for the points falling between 0-6 in colorscale,
paint red for the points falling between 6-18 in colorscale,
again paint black for the points falling between 18-24 in colorscale.
Any suggestions would be greatly appriciated.
scatter(X_axis_val,Y_axis_val,20,Z_axis_val)
MyColBar = [0 0 0; 1 0 0; 0 0 0];
colormap(MyColBar);
caxis([0 24]); colorbar;
The data is as attached below.
Thank you in advance.
댓글 수: 0
채택된 답변
DGM
2023년 2월 20일
편집: DGM
2023년 2월 20일
You can have a nonuniform discrete colorbar, but it's a bit convoluted:
Drawing from the examples at that link:
% some fake data
x = linspace(0,24,50);
y = x;
z = x;
% intervals/categories in Z (or C)
% the span of this vector defines caxis/clim
zb = [0 6 10/sqrt(2) 18 24];
% interval/category colors
CT0 = lines(numel(zb)-1);
% generate expanded color table & info
nmax = 256; % maximum table length
[CT cidx] = intervalct(zb,CT0,nmax);
cidx1 = cidx(:,2); % trailing block indices
% color data as an RGB color table
% this can be generated however you see fit (imquantize(), etc)
% note my assumption of behavior on bin edges
C = ones(size(z));
nk = numel(zb)-1;
for ck = 1:nk
if ck == 1
C(z<zb(2)) = 1;
elseif ck == nk
C(z>=zb(nk)) = nk;
else
C(z>=zb(ck) & z<zb(ck+1)) = ck;
end
end
C = ind2rgb(C,CT0); % convert to RGB
C = reshape(C,[],3); % reshape into Mx3 color table for use with scatter()
% plot the scatter
hs = scatter(x,y,20,C,'filled');
colormap(CT) % use the expanded colortable
cb = colorbar;
cb.Ticks = zb;
caxis(imrange(zb));
grid on
댓글 수: 0
추가 답변 (1개)
Walter Roberson
2023년 2월 20일
MyColBar = [0 0 0; 1 0 0; 1 0 0; 0 0 0];
You cannot have color sections of different widths, but you can duplicate colors.
참고 항목
카테고리
Help Center 및 File Exchange에서 Purple에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!