How to customize a color bar in matlab plot?

67 views (last 30 days)
I R
I R on 7 Dec 2017
Answered: DGM on 15 Jan 2023
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

Answers (3)

DGM
DGM on 15 Jan 2023
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 on 7 Dec 2017
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 on 7 Dec 2017
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 :)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!