Michaël Baudin

The goal of this page is to see the available color maps in Scilab.

The scripts

This page is inspired by Reynald Passerin's Scilab tools. But the code below is original, provided under the CeCILL.

Scilab provides several colormaps:

These colormaps can be used to color a plot, such as a 2D plot, 3D plot or a contour plot, for example.

The following script applies the autumn colormap to a 3D plot:

f = scf();
f.color_map = autumncolormap(32);

This produces the following plot.


The colormap function are difficult to automate. This is because there are so many function. Instead, we suggest to create one single function, which would take the name of the color as an input argument. This is why it is convenient to create some helper functions.

The following function returns the matrix of all available colormaps.

function cmapmatrix = colormap_all()
    // Returns all the available colormaps.
    // Copyright (C) 2011 - Michael Baudin
    cmapmatrix = [

The following function create a colormap given the number of colors and the name of a colormap.

function cmap = colormap_new(n,name)
    // Returns the color map given the number of colors and the name.
    // Copyright (C) 2011 - Michael Baudin
    cmapmatrix = colormap_all()
    // Check that the colormap is in the matrix
    k = find(name==cmapmatrix)
    if (k==[]) then
        error(gettext("%s: Undefined colormap %s\n"),"colormapnew",name)
    // Compute the colormap
    instr = "cmap = "+name+"colormap(n)"
    ierr = execstr(instr,"errcatch")
    if ( ierr<> 0 ) then
        lerr = lasterror()
        error(gettext("%s: %s\n"),"colormapnew",lerr)

The getcolor function is not very convenient, because it not only plot the colormap, but also forces an interaction with the user. It also customize the graphics window, which may not be necessary in some situations. Moreover, it creates a new window, while it may be interesting to plot the colormap within the current graphics window.

The following function prints the current colormap on the current figure. The algorithm is extracted from the code of the getcolor function.

 function colormap_print()
     // Prints the colormap on the current figure.
     // Copyright (C) 2011 - Michael Baudin
     fig = gcf();
     cmap = fig.color_map;

     N = size(cmap,1);
     wdim = [1,1];
     r = wdim(1)/wdim(2);
     n = round(sqrt(N/r));
     m = int(n*r);
     H = m*45; // These numbers set the size of the getcolor window
     W = n*45;
     fig.figure_size = [H,W];

     dx = wdim(1)/m;
     dy = wdim(2)/n;
     x = -dx;
     y = wdim(2);
     R = [0;0;dx*0.95;dy*0.95];
     rects = [];
     for k = 1:N
         if modulo(k,n)==1 then
             x = x+dx;
             y = wdim(2);
         rects = [rects,R+[x;y;0;0]];
         y = y-dy;

     // rectangles with the colors
     // frame around the colors
     r = m*n-N;
     ddx = 0.05*dx;
     ddy = 0.05*dy;
     if r==0 then


The following script performs a loop over the available colormaps. It creates a figure to plot the colormap and, if required, exports the content into a file.

 cmapmatrix = colormap_all();
 for c = cmapmatrix'
    h.color_map = colormap_new(n,c);
    // xs2png(h,c+".png"); Uncomment to create the files

The figures

The following figures presents the colormaps available in Scilab.

autumn: attachment:autumn.png

bone: attachment:bone.png

cool: attachment:cool.png

copper: attachment:copper.png

gray: attachment:gray.png

hot: attachment:hot.png

hsv: attachment:hsv.png

jet: attachment:jet.png

ocean: attachment:ocean.png

pink: attachment:pink.png

rainbow: attachment:rainbow.png

sprint: attachment:spring.png

summer: attachment:summer.png

white: attachment:white.png

winter: attachment:winter.png

A side note

Since we are really lazy, we updated the current wiki page by using Scilab to generate the links to the figures. The following script generates the content of the wiki page which is required.

 for c = cmapmatrix'

The previous script produces the following output.


public: howto/colormaps (last edited 2011-03-30 16:18:00 by localhost)