How to customize a color bar in matlab plot?

65 ビュー (過去 30 日間)
I R
I R 2017 年 12 月 7 日
回答済み: DGM 2023 年 1 月 15 日
I want to create a color bar similar to this one (see the attachment). The zero value is white and has different jet patterns on both side (positive and negative). Thanks

回答 (3 件)

DGM
DGM 2023 年 1 月 15 日
For what it's worth, here's the same colormap reconstructed. The map is PWL in RGB, so it's easy enough.
% generate a new CT from a list of breakpoints
N = 256; % new CT length
x = [0 48 84 128 168 199 256]/256;
CT0 = [1 0 1; 0 0 0.85; 0 1 1; 1 1 1; 0 1 0; 1 1 0; 1 0 0];
xf = linspace(0,1,N);
CT = interp1(x,CT0,xf,'linear','extrap');
% plot the channel trajectories (it's PWL)
plot(CT(:,1),'r'); hold on
plot(CT(:,2),'g')
plot(CT(:,3),'b')
% use the map to plot something
x = linspace(-pi/2,pi/2,30);
y = x.';
z = sin(x).*sin(y);
surf(x,y,z)
colormap(CT)
colorbar
view(-17,50)
Though there are many other bidirectional colormaps out there that would be better.

KSSV
KSSV 2017 年 12 月 7 日
c1 = jet ;
c2 = [1 1 1] ;
c3 = hsv ;
c = [c1 ; c2; c3] ;
[X,Y,Z] = peaks(100) ;
surf(X,Y,Z)
colorbar
colormap(c)

I R
I R 2017 年 12 月 7 日
Thanks for prompt reply. I tried your method but the transition from white to other colors is not smooth enough. Anyway, i have found an answer to my question here (https://www.mathworks.com/matlabcentral/fileexchange/36212-b2r-cmin-input-cmax-input-) Thanks again :)

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by