I want to change the color intervals in the colorbar in Scilab, in order not to have constant height of the different parts.
I was able to change the yticks location, and also the number of yticks,with the following code:
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));
But I couldn't find a way to change the position where the color change. I searched thorougly in the colorbar function, and I think that possibily the solution is in the following part of the function, but I am not pretty sure, and also I do not know how to change the code.
//draw the colorbar
y = linspace(umin,umax,nb_colors)
col=[colminmax(1):colminmax(2)]
Sgrayplot([0 1],y,[col;col],colminmax=colminmax)
To give a clearer idea of the desired results, see the following image. I want the boundary of the different colors to fall exactly where my yticks are.
One way to do this, is by defining your own colormap. Below is my custom "reversed" jetcolormap code. By changing the r
, g
, and b
arrays, you can modify the colors. If you don't need the flexibility for different number of colors, you can replace the interpolated cmap
values vith hardcoded ones. If you need unequal distances between color changes, simply define the same color more than once, i.e.: white, white, pink, red, red, red, ...
//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