2017-03-08 30 views
0

我想更改Scilab中彩條的顏色間隔,以便不會有不同部分的恆定高度。更改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) 

要更清楚地瞭解所需的結果,請參見下圖。我希望不同顏色的邊界恰好落在我的屁股所在的位置。要做到這一點

Deisred result

+0

難道我的回答讓你幫忙嗎? – Attila

+0

是的,它做到了!這是一個「週轉」解決方案,因爲如果我有無理間隔(例如,顏色1代表從0到pi的值,顏色2代表從pi到10的顏色),它不起作用。在這種情況下,我的cmap的長度需要非常大才能讓我的邊界落在準確的位置。我想更好地理解colorbar函數的工作原理,以及它如何繪製矩形,但同時,感謝您的答案! – Stefano

回答

0

的方法之一,是通過定義自己的顏色表。以下是我自定義的「反轉」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