Reputation: 351
I have a 3D plot using patch and the default colormap is jet as I am using R2014a.So I use
cMap=hsv(250);
colormap(cMap);
caxis([min(M(:)) max(M(:))]);
But when the value increase the color changes from deep blue to light blue then to deep red. It is not desirable for me as I want the color change from light color to deep color when the value increase. So how can I adjust the colormap so that it changes from, say light blue or white to deep red as the value increase? Thank you.
Upvotes: 2
Views: 11124
Reputation: 542
There are quite a few different colormaps, and you can make your own custom colormap too. Use doc colormap
to see them in more detail:
If you are using the HSV colormap and only seeing blue to red colours then it is because your colour axis limits are such that only that part of the colormap is being sampled. So if your data spans from 0.5 to 1.0 but you set the colour axis to caxis([0.0 1.0])
then you would only see half of the colours in the colormap.
In order to get a colormap like you describe, you can use this approach where you specify the minimum and maximum colours and create a colormap that blends from one to the other. Note that you will have to set your colour axis values according to the limits of your plot appropriately (commands like surf
automatically stretch to include all the colours).
% number of map indices
Nmap = 64;
% colormap from cyan to red
cMin1 = [0 1 1];
cMax1 = [1 0 0];
cMap1 = zeros(Nmap,3);
for i = 1:Nmap;
cMap1(i,:) = cMin1*(Nmap - i)/(Nmap - 1) + cMax1*(i - 1)/(Nmap - 1);
end
% colormap from white to red
cMin2 = [1 1 1];
cMax2 = [1 0 0];
cMap2 = zeros(Nmap,3);
for i = 1:Nmap;
cMap2(i,:) = cMin2*(Nmap - i)/(Nmap - 1) + cMax2*(i - 1)/(Nmap - 1);
end
% make up some data
Z = linspace(0,1,100)'*ones(1,100);
% plot with HSV colormap
figure
surf(Z,'edgealpha',0);
colormap('hsv');
% plot with cyan-to-red colormap
figure
surf(Z,'edgealpha',0);
colormap(cMap1);
% plot with white-to-red colormap
figure
surf(Z,'edgealpha',0);
colormap(cMap2);
Which should produce:
Upvotes: 4