Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB Get a list of color map names

I am writing a GUI that would benefit from a user-selection of colormaps by name. However, I am at a bit of a quandary in that I can't seem to programmatically get a list of supported colormap names!

While I could hardcode the names; my code may be run on older versions of matlab which may have different colormaps. My primary concern is with the parula colormap which, if I recall correctly, was not present in MATLAB 2014.

Any thoughts?

like image 621
warpstack Avatar asked May 11 '16 14:05

warpstack


People also ask

What is Colormap Matlab?

A colormap is a matrix of values that define the colors for graphics objects such as surface, image, and patch objects. MATLAB® draws the objects by mapping data values to colors in the colormap. Colormaps can be any length, but must be three columns wide. Each row in the matrix defines one color using an RGB triplet.

How do you show Colormap in Matlab?

Starting in R2019b, you can display a tiling of plots using the tiledlayout and nexttile functions. Call the tiledlayout function to create a 2-by-1 tiled chart layout. Call the nexttile function to create the axes. Then display a surface plot in each axes with a colorbar.

How do you use colormap jet in Matlab?

Description. c = jet returns the jet colormap as a three-column array with the same number of rows as the colormap for the current figure. If no figure exists, then the number of rows is equal to the default length of 256. Each row in the array contains the red, green, and blue intensities for a specific color.

How many colors are available in Matlab?

The eight basic colors are known by either their short name or long name (RGB triplets are also included). Example of how to change the color using short names is below.


4 Answers

Alternatively, you can hardcode them and have an if statement with graphicsversion(fhandle) on it.

It returns returns true if the default graphics system is the old handle graphics one.


You could also try to get an extensive list, and then check if colormapname.m is a file in matlabroot\toolbox\matlab\graph3d. If the function is there, the colormap comes in that version. You'd still need to hardcode an extensive list though.

EDIT: as @thewaywewalk suggests, you could open Contents.min matlabroot\toolbox\matlab\graph3d and esarch for % Color maps. It has a list of the colormaps included in the version. In 2014b its on lines 29-48

like image 164
Ander Biguri Avatar answered Oct 26 '22 07:10

Ander Biguri


I'm not 100% sure it works in MATLAB As @BillBokeey points out in the comments this does not work in MATLAB, but in Octave you can use:

CM = colormap('list');

It will return a cell array of strings containing all of the valid colormaps.

CM =
{
  [1,1] = autumn
  [1,2] = bone
  [1,3] = cool
  [1,4] = copper
  [1,5] = flag
  [1,6] = gmap40
  [1,7] = gray
  [1,8] = hot
  [1,9] = hsv
  [1,10] = jet
  [1,11] = lines
  [1,12] = ocean
  [1,13] = pink
  [1,14] = prism
  [1,15] = rainbow
  [1,16] = spring
  [1,17] = summer
  [1,18] = white
  [1,19] = winter
}
like image 25
beaker Avatar answered Oct 26 '22 07:10

beaker


A possibility to get an extensive list of available colormaps :

In matlabroot\help\matlab\ref, you can find previews of all available colormaps whose filenames are of the form colormap_colormapname.png

In order to get your list, you can use :

CurrFolder=pwd;

cd(strcat(matlabroot,'\help\matlab\ref'))

Colormaps=dir('*colormap_*.png');

TmpColormapsList={Colormaps.name};

TmpColormapsList=cellfun(@(S)strrep(S,'colormap_',''),TmpColormapsList,'UniformOutput',false);

ColormapsList=cellfun(@(S)strrep(S,'.png',''),TmpColormapsList,'UniformOutput',false);

cd(CurrFolder);

This will output a cell array of string containing the names of the available colormaps.

Pretty ugly hack, but at least it works on 2014b (Please check it for your version if you have another one)

like image 23
BillBokeey Avatar answered Oct 26 '22 08:10

BillBokeey


Another way (hack) might be to extract the string out the the colormapeditor function:

colormapeditorString = fileread(strcat(matlabroot,'\toolbox\matlab\graph3d\colormapeditor.m'));
posStart = strfind(colormapeditorString,'stdcmap(maptype');
posEnd = strfind(colormapeditorString(posStart:end),'end') + posStart;
stdcmapString = colormapeditorString(posStart:posEnd);
split = strsplit(stdcmapString, '(mapsize)');
list = cellfun(@(x)x(find(x==' ', 1,'last'):end), split,'uni',0);
list(end) = [];
like image 26
Dan Avatar answered Oct 26 '22 09:10

Dan