Hi Antoine,

Please find here below improved code to plot with breaks, using a function 
"plotbreaks":

// Multiple axis breaks in Scilab (2nd attempt)
// START OF CODE

clear;

function []=plotbreaks(x0,y0,dx_break);
// x0 and y0 are 1D arrays to plot with breaks
    [x0,k] = gsort(x0,'g','i');
    y0= y0(k);
    k=1;
    dxtick = stdev(x0)/4;  // try to plot ticks every dxtic
    xb= list();
    yb= list();
    xb(1) = x0(1);
    yb(1) = y0(1);
    for i=1:length(x0)-1
        if abs(x0(i+1)-x0(i)) < dx_break then
            xb(k)= [xb(k) x0(i+1)];
            yb(k)= [yb(k) y0(i+1)];
        else
            k= k+1;
            xb(k) = x0(i+1);
            yb(k) = y0(i+1);
        end
    end
    ymin = min(y0)-0.1*stdev(y0);
    xn=1;
    xi0 = 0;
    for i=1:k
        li = length(xb(i));
        xi = x0(xn:xn+li-1) - xi0;
        val1 = xb(i)(1):dxtick:xb(i)($);
        if val1($)<>xb(i)($) then val1=[val1 xb(i)($)]; end
        xaxis = linspace(xi(1),xi($),length(val1));
        plot2d(xi,yb(i),axesflag=0)
        // TODO: improve grid display & fill gaps with light-gray color
        xgrid(color("grey70"));  //a better grid style:
        a = gca();
        a.grid_style=[8 8]; 
        val2 = [];
        for j=1:length(val1)
            val2= [val2 msprintf("%.1f",val1(j))];
        end
        drawaxis(x=xaxis,y=ymin,dir='d',tics='v', val=val2)
        xn = xn + li;
        if i<k then
           xi0= x0(xn) - xi($) - dxtick/4;
        end
    end
    f=gcf();
    f.children.axes_visible = ["off","on","on"]
endfunction


clf();
x0=[-7.5:0.1:10 20.1:0.33:25 60:0.25:100];
y0= exp(x0/30).*(1+0.5*sin(x0));
dx_break= 3; // adjust this threshold to define breaks

a=plotbreaks(x0,y0,dx_break)

//END OF CODE


Regards,
Rafael


-----Original Message-----
From: users [mailto:users-boun...@lists.scilab.org] On Behalf Of Antoine 
Monmayrant
Sent: Tuesday, November 22, 2016 1:31 PM
To: users@lists.scilab.org
Subject: [Scilab-users] Axis break with Scilab ?

Hi all,

I just got a question from one of my colleagues: "Is this possible to get axis 
breaks when plotting with Scilab?"
(ie a plot where a bit of the scale in x, y or even both is missing, see : 
http://www.originlab.com/doc/Tutorials/Multiple-Axis-Breaks ).
As far as I know, I don't see any direct way to do it.

Am I wrong?

As for workaround, I think one could achieve similar results with subplots and 
visible/hidden axis, but it would require a bit of overhead ...

Cheers,

Antoine


_______________________________________________
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

Reply via email to