[Scilab-users] Axis break with Scilab ?

Rafael Guerra jrafaelbguerra at hotmail.com
Fri Nov 25 19:00:44 CET 2016


Dear Scilabers,

Sorry to post yet another version but known errors should not remain uncorrected.
The revised snippet below produces the attached figure.


// Multiple x-axis breaks in Scilab (4th attempt)
// START OF CODE

clear;

function []=plotxbreaks(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();
    xi= list();
    xaxis = list();
    xi0 = 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);
    xn=1;
    xi0(1) = 0;
    for i=1:k
        li = length(xb(i));
        xi(i) = x0(xn:xn+li-1) - xi0(i);
        ni = ceil((xb(i)($)-xb(i)(1))/dxtick)+1;
        xaxis(i) = linspace(xb(i)(1),xb(i)($),ni);
        plot2d(xi(i),yb(i),axesflag=0)
        val2 = [];
        for j=1:length(xaxis(i))
            val2= [val2 msprintf("%.1f",xaxis(i)(j))];
        end
        drawaxis(x=xaxis(i)-xi0(i),y=ymin-0.1*stdev(y0),dir='d',tics='v', val=val2)
        xn = xn + li;
        if i<k then
            xi0(i+1)= x0(xn) - xi(i)($) - dxtick/3;  // display gaps of width dxtick/3
        end
    end

    f=gcf();
    f.children.axes_visible = ["off","on","on"];
    xgrid(color("gray"));
    a = gca();
    a.grid_style=[8 8]; 
    for i=1:k-1
        ymin = a.y_ticks.locations(1);
        ymax = a.y_ticks.locations($);
        rects= [xi(i)($);ymax;dxtick/3;ymax-ymin];
        xrects(rects,color("grey95"));  //"lavenderblush"
    end
    for i=1:k;
        for j=1:length(xaxis(i))
            xpoly([xaxis(i)(j)-xi0(i);xaxis(i)(j)-xi0(i)],[ymax;ymin]);
            e=gce();
            e.line_style=8;
            e.foreground= color("gray"); 
         end
    end
endfunction


clf();
x0= [-10:0.1:9 21:0.5:34 55:0.25:66]; // x-input
y0= exp(x0/20).*(1+0.3*sin(x0));  // y-input
dx_break= 3; // adjust x-breaks threshold (data dependent)
plotxbreaks(x0,y0,dx_break)

//END OF CODE


Regards,
Rafael

-------------- next part --------------
A non-text attachment was scrubbed...
Name: plotbreaks.pdf
Type: application/pdf
Size: 16731 bytes
Desc: plotbreaks.pdf
URL: <https://lists.scilab.org/pipermail/users/attachments/20161125/3fbcbf6d/attachment.pdf>


More information about the users mailing list