更改 scilab colorbar 中的颜色间隔

Change color intervals in scilab colorbar

我想在 Scilab 中更改颜色栏中的颜色间隔,以免不同部分的高度保持不变。

我可以使用以下代码更改 yticks 位置以及 yticks 的数量:

fig= gcf();
   cb = fig.children(1);
   cb.font_size = 3;
   cb.auto_ticks(2)="off";
   cb.y_ticks = tlist(["ticks","locations","labels"], yticks, string(yticks));

但是我找不到改变颜色变化位置的方法。我在 colorbar 函数里搜了一大圈,我觉得可能是在函数后面的部分解决,但是我不是很确定,而且我也不知道怎么改代码。

   //draw the colorbar
    y = linspace(umin,umax,nb_colors)
    col=[colminmax(1):colminmax(2)]
    Sgrayplot([0 1],y,[col;col],colminmax=colminmax)

为了更清楚地了解所需的结果,请参见下图。我希望不同颜色的边界正好落在我的 yticks 所在的位置。

Deisred result

实现此目的的一种方法是定义您自己的颜色图。下面是我的自定义 "reversed" jetcolormap 代码。通过更改 rgb 数组,您可以修改颜色。如果您不需要不同数量颜色的灵活性,您可以用硬编码值替换内插的 cmap 值。如果您需要颜色变化之间的距离不等,只需多次定义相同的颜色,即:白色,白色,粉红色,红色,红色,红色,...

//modification from jetcolormap
//reversing color order
function [cmap] = reverse_jetcolormap(varargin)
    // Check number of input argument
    if size(varargin)<>1 then
        error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"), "reverse_jetcolormap", 1));
    end
    n=varargin(1);

    // Check type of input argument
    if typeof(n)<>"constant" then
        error(msprintf(gettext("%s: Wrong type for input argument #%d: An integer value expected.\n"), "reverse_jetcolormap", 1));
    end

    // Check if input argument is real
    if ~isreal(n) then
        error(msprintf(gettext("%s: Wrong type for input argument #%d: An integer value expected.\n"), "reverse_jetcolormap", 1));
    end

    // Check size of input argument
    if size(n,"*")<>1 then
        error(msprintf(gettext("%s: Wrong size for input argument #%d: An integer value expected.\n"), "reverse_jetcolormap", 1));
    end

    if n==0 then
        cmap = [];
        return
    end


//    r = [0.000 0.125 0.375 0.625 0.875 1.000 ; 0.000 0.000 0.000 1.000 1.000 0.500]
//    g = [0.000 0.125 0.375 0.625 0.875 1.000 ; 0.000 0.000 1.000 1.000 0.000 0.000]
//    b = [0.000 0.125 0.375 0.625 0.875 1.000 ; 0.500 1.000 1.000 0.000 0.000 0.000]

    r = [0.000 0.125 0.375 0.625 0.875 1.000 ; 0.500 1.000 1.000 0.000 0.000 0.000]
    g = [0.000 0.125 0.375 0.625 0.875 1.000 ; 0.000 0.000 1.000 1.000 0.000 0.000]
    b = [0.000 0.125 0.375 0.625 0.875 1.000 ; 0.000 0.000 0.000 1.000 1.000 0.500]

    d = 0.5/max(n,1);
    x = linspace(d,1-d, n)
    cmap = [ interpln(r, x);...
    interpln(g, x);...
    interpln(b, x) ]';
    cmap = min(1, max(0 , cmap))  // normaly not necessary
endfunction