[Scilab-users] Axis break with Scilab ?
Rafael Guerra
jrafaelbguerra at hotmail.com
Fri Nov 25 15:32:17 CET 2016
Hello,
There was a silly mistake in the labeling in the previous code sample posted.
In order to try keeping a clean record, here it goes an improved version of plotxbreaks(), which produces the plot attached.
// Multiple axis breaks in Scilab (3rd attempt)
// START OF CODE
clear;
function []=plotxbreaks(x0, y0, dx_break);
// x0 and y0 are 1D arrays to plot with breaks greater than dx_break
[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();
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 = 0;
for i=1:k
li = length(xb(i));
xi(i) = x0(xn:xn+li-1) - xi0;
val1 = xb(i)(1):dxtick:xb(i)($);
if val1($)<>xb(i)($) then val1($)=xb(i)($); end
xaxis(i) = linspace(xi(i)(1),xi(i)($),length(val1));
xn = xn + li;
if i<k then
xi0= x0(xn) - xi(i)($) - dxtick/4;
end
plot2d(xi(i),yb(i),axesflag=0)
val2 = [];
for j=1:length(val1)
val2= [val2 msprintf("%.1f",val1(j))];
end
drawaxis(x=xaxis(i),y=ymin-0.1*stdev(y0),dir='d',tics='v', val=val2)
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/4;ymax-ymin];
xrects(rects,color("grey95")); //or "lavenderblush"
end
for i=1:k;
for j=1:length(xaxis(i))
xpoly([xaxis(i)(j);xaxis(i)(j)],[ymax;ymin]);
e=gce();
e.line_style=8;
e.foreground= color("gray");
end
end
endfunction
clf();
x0=[-7.5:0.1:10 20.1:0.33:35 55:0.25:66];
y0= exp(x0/20).*(1+0.3*sin(x0));
dx_break= 3; // adjust this threshold to define x-axis breaks
plotxbreaks(x0,y0,dx_break)
//END OF CODE
Regards,
Rafael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20161125/9a553527/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plotxbreaks.pdf
Type: application/pdf
Size: 14931 bytes
Desc: plotxbreaks.pdf
URL: <https://lists.scilab.org/pipermail/users/attachments/20161125/9a553527/attachment.pdf>
More information about the users
mailing list