【问题标题】:Change color intervals in scilab colorbar更改 scilab 颜色栏中的颜色间隔
【发布时间】:2017-03-08 08:48:39
【问题描述】:

我想更改 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

【问题讨论】:

  • 我的回答对你有帮助吗?
  • 是的,它做到了!这是一个“周转”解决方案,因为在我有不合理的间隔时它不起作用(例如,颜色 1 表示从 0 到 pi 的值,颜色 2 表示从 pi 到 10 的颜色)。在这种情况下,我的 cmap 的长度需要很大,以便让我的边界落在确切的位置。我想更好地了解 colorbar 函数是如何工作的,以及它是如何绘制矩形的,但与此同时,感谢您的回答!

标签: plot colorbar scilab


【解决方案1】:

一种方法是定义您自己的颜色图。下面是我自定义的“反向”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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    • 2021-04-27
    相关资源
    最近更新 更多