How to create rainbow colormap with violet
Show older comments
Hi,
I am familiar with the 'jet' colormap which is actually the rainbow colormap.
But, I want to add to this colormap (or create a new one), which is still a rainbow colormap, but would start from violet for the low levels (instead of blue).
Any idea how can I achive this?
Would appreciate youe kind response/
O.
Accepted Answer
More Answers (2)
Turlough Hughes
on 4 Jan 2022
Edited: Turlough Hughes
on 4 Jan 2022
Violet is approximately [0.5 0 1] in the rgb space.
So we can modify the blue part of the jet colormap, to have a bit more red as follows:
cmap = jet(256);
cmap(1:find(cmap(:,1)==0.5),1) = 0.5;
hf = figure('Units','normalized');
colormap(cmap)
hCB = colorbar('north');
set(gca,'Visible',false)
hCB.Position = [0.15 0.3 0.74 0.4]; % edit just removes some whitespace
hf.Position(4) = 0.1000;
5 Comments
omri r
on 4 Jan 2022
Turlough Hughes
on 4 Jan 2022
Edited: Turlough Hughes
on 4 Jan 2022
Ok I see what you mean. The following seems pretty close:
cmap = jet(181);
colorA = [0 0 0];
colorB = [0.8 0 0.5];
colorC = [0.5 0 1]; % Violet
n = 26;
partA = linspaceRows(colorA, colorB, n);
partB = linspaceRows(colorB, colorC, n);
partC = linspaceRows(colorC, cmap(1,:), n);
cmap = [partA(1:end-1,:); partB(1:end-1,:); partC(1:end-1,:); cmap];
hf = figure('Units','normalized');
colormap(cmap)
hCB = colorbar('north');
set(gca,'Visible',false)
hCB.Position = [0.15 0.3 0.74 0.4];
hf.Position(4) = 0.1000;
function map = linspaceRows(rowA, rowB, n)
map = ...
[linspace(rowA(1),rowB(1), n).',...
linspace(rowA(2),rowB(2), n).',...
linspace(rowA(3),rowB(3), n).'];
end
figure
surf(peaks(256))
colormap(turbo(256))
colorbar
shading('interp')
The ‘cool’ end appears to me to be violet. See Compare Jet and Turbo Colormaps for more information about both.
.
Turlough Hughes
on 4 Jan 2022
Hmm, yea... on second thought, maybe the answer should be "don't use a rainbow colormap".
The following would be worth reading:
omri r
on 5 Jan 2022
Image Analyst
on 4 Jan 2022
The MATLAB built-in "turbo" colormap is nice.
cmap = turbo(256);
colormap(cmap)
colorbar('north')
set(gca,'Visible',false)
No violet, but better than jet.

Categories
Find more on Color and Styling 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!






