How to customize a color bar in matlab plot?
67 views (last 30 days)
Show older comments
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
0 Comments
Answers (3)
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.
0 Comments
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)
0 Comments
See Also
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!