[Scilab-users] Axis break with Scilab ?
Dang Ngoc Chan, Christophe
Christophe.Dang at sidel.com
Wed Nov 23 11:33:29 CET 2016
OK,
I played a little bit with this,
and I’ve got some ugly side-effects.
I’ve no doubt this can be solved,
Anyway, it is a bit more complicated than it appears.
The following code is just for a break on the X-axis,
and it has only be tested for the example provided ;
though all my efforts, it’s probably not a boiler-plate.
And the result is anyhow not satisfying.
function []=break_axis(X, Y, minbreakX, maxbreakX, breaksize)
// draw the curve in two separated intervals
// [min(X) ; minbreakX] and [maxbreakX ; max(X)]
// X is a sorted vector of reals
// Y is a vector of reals of the same size as X
// breaksize is the width of the break expressed as a fraction of one
//
// defining the subwindows
bool1 = (X <= minbreakX);
bool2 = (X >= maxbreakX);
sizeX1 = minbreakX - X(1);
sizeX2 = X($) - maxbreakX;
invfullsizeX = 1/((1 + breaksize)*(sizeX1 + sizeX2));
minY1 = min(Y(bool1)); maxY1 = max(Y(bool1));
sizeY1 = maxY1 - minY1;
minY2 = min(Y(bool2)); maxY2 = max(Y(bool2));
sizeY2 = maxY2 - minY2;
maxY = max(Y); minY = min(Y);
invfullsizeY = 1/(maxY - minY);
rect_for_xsetech1 = [0, 1 - maxY1*invfullsizeY,...
sizeX1*invfullsizeX, sizeY1*invfullsizeY];
rect_for_xsetech2 = [sizeX1*invfullsizeX + breaksize,...
1 - maxY2*invfullsizeY, 1 - sizeX2*invfullsizeX, sizeY2*invfullsizeY];
// Defining the axes
[Yi, Ya, npY] = graduate(min(Y), max(Y));
[X1i, X1a, npX1] = graduate(X(1), max(X(bool1)));
rectX1 = [X1i, Yi, X1a, Ya];
Xtics1 = linspace(X1i, X1a, npX1);
[X2i, X2a, npX2] = graduate(min(X(bool2)), X($));
rect2 = [X2i, Yi, X2a, Ya];
Xtics2 = linspace(X2i, X2a, npX2);
// drawing the left part :
xsetech(rect_for_xsetech1);
plot(X(bool1), Y(bool1));
axis1 = gca();
axis1.axes_visible=["off", "off", "off"];
axis1.box="off";
drawaxis(x=Xtics1, y=minY-minY1, dir="u", tics="v");
// drawing the right part :
xsetech(rect_for_xsetech2);
plot(X(bool2), Y(bool2));
axis2 = gca();
axis2.axes_visible=["off", "off", "off"];
axis2.box="off";
drawaxis(x=Xtics2, y=minY-minY2, dir="u", tics="v");
// drawing the Y axis
xsetech([0, 0, 1, 1]);
Ytics = linspace(Yi, Ya, npY);
Yticscoord = Ytics./(Ya - Yi);
Yticslabels = string(Ytics);
finalaxisY = drawaxis(y=Yticscoord, dir="l", tics="v");
finalaxisY.tics_labels=Yticslabels;
endfunction
// test program
clf();
X=0:10;
Y = X.^2;
break_axis(X, Y, 3, 5, 0.05);
--
Christophe Dang Ngoc Chan
Mechanical calculation engineer
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20161123/f914b29f/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: X_axis_break.png
Type: image/png
Size: 4388 bytes
Desc: X_axis_break.png
URL: <https://lists.scilab.org/pipermail/users/attachments/20161123/f914b29f/attachment.png>
More information about the users
mailing list