Unevenly Map Data to an RGB Map?
Afficher commentaires plus anciens
So I have made an RGB style map that mimics Matlab's color map options (just a different flavor, for stylistic reasons), and I want it to scale to the bottom two thirds of my data. I want it to linearly scale to the bottom two thirds because the peaks are so high that a perfect linear match hides small-scale detail elsewhere in the figures. Any good tricks?
For context, I'm plotting with surfc and then:
load('rgbmap.mat'); %Homemade colormap stored here as variable "map"
colormap(map);
c = colorbar;
Thank you.
1 commentaire
Mohammad Sami
le 19 Sep 2020
The easiest way would be to edit the colour map in the figure GUI.
Réponse acceptée
Plus de réponses (2)
Mohammad Sami
le 19 Sep 2020
0 votes
You can use the colormapeditor GUI to interactively create the colour map.
https://www.mathworks.com/help/matlab/ref/colormapeditor.html
If you want to take your colormap and shift it toward one end or the other for some reason, you might be able to do something like this:
% say you have some colormap
cmap0 = parula(64);
% scale adjustment parameter (range is [-1 1])
% when stretchamt = 0, no change
% when stretchamt < 0, stretch bottom of table upward
% when stretchamt > 0, stretch top of table downward
stretchamt = 0.5;
% delinearize adjustment parameter to get gamma
% apply gamma adjustment to primary axis of the CT
% conditionally flip table so xnew is effectively point-symmetric about [0.5 0.5]
% this limits the slope of xnew and avoids overcompressing the table for g<1
n = size(cmap0,1);
x = linspace(0,1,n);
if stretchamt > 0
g = 1 - min(1-eps,stretchamt);
xnew = x.^(1/g);
cmapnew = flipud(interp1(x,flipud(cmap0),xnew,'pchip'));
else
g = 1/(1 + max(eps-1,stretchamt));
xnew = x.^g;
cmapnew = interp1(x,cmap0,xnew,'pchip');
end
% cmapnew is your new color table
cmapnew
For sake of visualization, this is what the results look like for stretchamt equal to -0.6, -0.3, 0, 0.3, and 0.6 respectively

For a prebuilt tool that does this, see ctshift() from MIMT (on the File Exchange)
Catégories
En savoir plus sur Lighting, Transparency, and Shading dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!