View Raw SPL
/* set shading for plot and possible colorbar */
setplotshading(rgb)
{
        local nc, f, j;

        if (argc < 1)
        {
                rgb = {};
        }        

        /* num overlays */
        nc = getfocus(-1);

        /* current focus */
        f = getfocus();

        if (not(isempty(rgb)))
        {
                rgb = setplotshading_limit(rgb);
                setcolormap(rgb);
        }

        setshading();

        loop (j = (f+1)..nc)
        {
                focus(j);

                if (getcomment() == "Color Legend")
                {
                        setshading();
                }
        }

        focus(f);
}


/* limit colormap to 256 shades */
setplotshading_limit(rgb)
{
        if (length(rgb) > 256)
        {
                rgb = xylookup(linspace(0, 255, length(rgb)), rgb, 0..255);

                /* remove X columns */
                rgb = rgb[.., 1..2..6];
        }

        return(rgb);
}