Search code examples
matlabscilabcolorbarsurface

Scilab : Same colorbar for two subplots


I have two variables (z1 and z2) which are function of x and y. I would like to plot them in two subplot using the same colorbar. These two variables have different min and max value. So, I would like define the colorbar as begining by the min of (z1,z2) and finishing by the max of (z1,z2). Therefore I use:

figure=scf();
figure.color_map=jetcolormap(32);
subplot1=subplot(121);
surf(x,y,z1);
subplot2=subplot(122);
surf(x,y,z2);
colorbar(min(min(min(z1)),min(min(z2))),max(max(max(z1)),max(max(z2))));

But doing like this, I get two graph using theirs own colorbar which correspond respectively to their min and max. I know that we can get this behaviour on Matlab using properties as caxis and clim. But I don't know the equivalent of these properties for Scilab.

If it's not possible to do this with the basic version of Scilab, could you please advise to me some libraries Scilab permitting to do this.

Thanks for your help.


Solution

  • You may try to change the cdata_mapping from 'scaled' to 'direct' and scale the color matrix (which defines the color of each facet) according to the actual range used:

    x=[0:0.3:2*%pi];   //example data
    [X,Y]=ndgrid(x,x);
    Z1=sin(x')*cos(x);    //first data set
    Z2=Z1./2;    //second dataset is half in amplitude
    
    Zmin=min(min(Z1),min(Z2));    //Absolut minimum of all data sets
    Zmax=max(max(Z1),max(Z2));    //Absolut maximum of all data sets
    nc=100;   //number of colors in colormap
    
    tabl=scf();
    tabl.color_map=jetcolormap(nc);
    subplot(1,2,1);
    surf(X,Y,Z1);
    h=gce();
    cm=h.data.color;   //color matrix
    h.data.color=((cm-Zmin)./(Zmax-Zmin)).*(nc-1)+1;   //scale color matrix & convert to color number
    h.cdata_mapping="direct";   //change color mapping from 'scaled' to 'direct'
    colorbar(Zmin,Zmax);
    
    subplot(1,2,2);
    surf(X,Y,Z2);
    h=gce();
    cm=h.data.color;   //color matrix
    h.data.color=((cm-Zmin)./(Zmax-Zmin)).*(nc-1)+1;   //scale color matrix & convert to color number
    h.cdata_mapping="direct";   //change color mapping from 'scaled' to 'direct'
    colorbar(Zmin,Zmax);