Claus Futtrup |
Dear Scilabers I am trying to make a kind-of 3D plot, but with lines (in 2D). Attached a file that shows what I wish to do. Below some code that shows current state, but given the desired result (attached), I'm not happy with it. I'm "cheating" a bit to make plot3d accept my input data and I Wonder if I'm on the wrong track? Best regards, Claus // Test data frequencies = [201 811 3183 12862 25113]; // Hz angles = [0 30 60 90]; // off-axis angles, degrees m_norm = [ 1.0 0.9945629 0.9643959 0.8756431; 1.0 0.9914442 1.0244046 0.9414654; 1.0 0.9910279 0.9670986 0.8932413; 1.0 0.9339808 0.8378147 0.7067978; 1.0 0.8985782 0.7536068 0.5074218]; s2d = scf(); for i=1:length(angles) do plot(frequencies,m_norm(:,i),'-k'); end sa2d = gca(); sa2d.log_flags = "lnn"; // log x-axis // Instead of above "flat" 2D plot, // now stack the plots in a 3D plot stackplt = scf(); sp = gca(); // Get current axis handle for i=1:length(angles) do anglei = [angles(i)-0.1 angles(i)+0.1]; // make size of arguments = 2 mi = [m_norm(:,i) m_norm(:,i)]; // so that it becomes a small surface plot3d(frequencies,anglei,mi,alpha=85,theta=85,flag=[2,2,3]); // plot3d(frequencies,angles,m_norm(:,i)); // above command creates error plot3d: // Wrong size for input arguments #2 and #3: >= 2 expected. end // plot3d(frequencies,angles,m_norm,alpha=85,theta=85,flag=[2,2,3]); // This plot expects a "surface" - doesn't work for lines sp.log_flags = "lnn"; // log x-axis (frequencies) _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users YG%2520anat%2520off%2520axis.jpg (40K) Download Attachment |
Hi Claus,
Try the following code using param3d:
// START
OF CODE
frequencies
=
[201
811
3183 12862
25113]';
// Hz; row vector
angles
=
[0
30
60 90];
// off-axis angles, degrees
m_norm
=
[ 1.0
0.9945629
0.9643959
0.8756431;
1.0
0.9914442
1.0244046
0.9414654;
1.0
0.9910279
0.9670986
0.8932413;
1.0
0.9339808
0.8378147
0.7067978;
1.0
0.8985782
0.7536068
0.5074218];
clf();
sp
=
gca();
// Get current axis handle
for
i=1:length(angles)
do
anglei
= angles(i)
+
zeros(m_norm(:,i))
mi
=
20*log10(m_norm(:,i));
// dB scale
param3d(frequencies,anglei,mi,alpha=50,theta=-110,flag=[2,4]);
//
e
= gce()
//the handle on the 3D polyline
e.foreground
=
color('dark blue');
e.thickness
=
2;
end
xgrid;
sp.log_flags
=
"lnn";
// x-axis log scale (frequencies)
sp.cube_scaling
=
"on";
xlabel("Frequency
(Hz)");
ylabel("Angle
(deg)");
zlabel("Mag
(dB)");
// END OF
CODE
Regards,
Rafael
_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
In reply to this post by Claus Futtrup
Hello Claus,
plot3d3() may be used for this kind of plot. It is even its main asset, despites it is not highlighted in its documentation. Here is an enriched version of its example, and its rendering: u = linspace(-%pi/2, %pi/2, 30); v = linspace(0, 2*%pi, 30); X = cos(u)'*cos(v); Y = cos(u)'*sin(v); Z = sin(u)'*ones(v); clf subplot(1,3,1) plot3d3(X,Y,Z); subplot(1,3,2) plot3d3(X,Y,Z); ax = gca(); ax.children(1).visible = "off"; ax.children(2).children.foreground = color("grey70"); subplot(1,3,3) plot3d3(X,Y,Z); ax = gca(); ax.children(2).visible = "off"; ax.children(1).children.foreground = color("orange"); f = gcf(); isoview(f) f.children.rotation_angles = [50 20];As you see, plot3d3() plots two independent sub-lattices that can be controlled independently. This may be easily applied to your case. If you don't need one of the sub-lattices, you may even delete it and keep only the other one. Cheers Samuel PS : i will propose an improved page for plot3d3. _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
In reply to this post by Claus Futtrup
Claus,
You can also try param3d1, which needs to be called only once:
// START OF CODE
frequencies = [201 811 3183 12862 25113]; // Hz;
angles = [0 30 60 90]; // degrees
m_norm = [ 1.0 0.9945629 0.9643959 0.8756431;
1.0 0.9914442 1.0244046 0.9414654;
1.0 0.9910279 0.9670986 0.8932413;
1.0 0.9339808 0.8378147 0.7067978;
1.0 0.8985782 0.7536068 0.5074218];
[nf na] = size(m_norm)
A = (angles .*. ones(nf,1))';
F = (frequencies .*. ones(na,1));
M = 20*log10(m_norm'); // dB scale
clf();
sp = gca();
param3d1(F,A,M,alpha=50,theta=-110,flag=[2,4]);
e = gce();
for i=1:nf;
e.children(i).foreground = color('dark blue');
e.children(i).thickness = 2;
end
xgrid;
sp.log_flags = "lnn"; // x-axis log scale (frequencies)
sp.cube_scaling = "on";
xlabel("Frequency (Hz)");
ylabel("Angle (deg)");
zlabel("Mag (dB)");
// END OF CODE
Regards,
Rafael
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com. _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
In reply to this post by Rafael Guerra
Claus,
You can also try param3d1, which needs to be called only once: // START OF CODE frequencies = [201 811 3183 12862 25113]; // Hz; angles = [0 30 60 90]; // deg m_norm = [ 1.0 0.9945629 0.9643959 0.8756431; 1.0 0.9914442 1.0244046 0.9414654; 1.0 0.9910279 0.9670986 0.8932413; 1.0 0.9339808 0.8378147 0.7067978; 1.0 0.8985782 0.7536068 0.5074218]; [nf na] = size(m_norm) A = (angles .*. ones(nf,1))'; F = (frequencies .*. ones(na,1)); M = 20*log10(m_norm'); // dB scale clf(); sp = gca(); param3d1(F,A,M,alpha=50,theta=-110,flag=[2,4]); e = gce(); for i=1:nf; e.children(i).foreground = color('dark blue'); e.children(i).thickness = 2; end xgrid; sp.log_flags = "lnn"; // x-axis log scale (frequencies) sp.cube_scaling = "on"; xlabel("Frequency (Hz)"); ylabel("Angle (deg)"); zlabel("Mag (dB)"); // END OF CODE Regards, Rafael _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Hello Rafael,
About param3d() and param3d1(): In 3 days, it will be the 10th birthday of this report: http://bugzilla.scilab.org/6155 Shall we make a present to other users? :) By the way, beyond their pages, don't you think the functions themselves should be merged? Le 28/01/2018 à 16:39, Rafael Guerra a écrit : > .../... > for i=1:nf; > e.children(i).foreground = color('dark blue'); > e.children(i).thickness = 2; > end Or more simply: e.children.foreground = color('dark blue'); e.children.thickness = 2; This kind of vectorized assignment (almost always) works. Cheers Samuel _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Hi Samuel,
Absolutely, the two param3d functions should be merged. The vectorised assignment example should also be included in the helpfile. Regards, Rafael -----Original Message----- From: users [mailto:[hidden email]] On Behalf Of Samuel Gougeon Sent: Sunday, January 28, 2018 5:17 PM To: Users mailing list for Scilab <[hidden email]> Subject: Re: [Scilab-users] Stacked 2D plot in 3D Hello Rafael, About param3d() and param3d1(): In 3 days, it will be the 10th birthday of this report: http://bugzilla.scilab.org/6155 Shall we make a present to other users? :) By the way, beyond their pages, don't you think the functions themselves should be merged? Le 28/01/2018 à 16:39, Rafael Guerra a écrit : > .../... > for i=1:nf; > e.children(i).foreground = color('dark blue'); > e.children(i).thickness = 2; > end Or more simply: e.children.foreground = color('dark blue'); e.children.thickness = 2; This kind of vectorized assignment (almost always) works. Cheers Samuel _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Hi Rafael and Samuel Thank you both for great suggestions - and as I thought - I was on the wrong path. Indeed I looked at plot3d3 and didn't catch that this one is suitable for what I wish to do. I see clearly with the example by Samuel that it is quite a smart way. I initially made the mistake to feed vectors (frequencies + angles), and it complained (and it revealed, it seems, that plot3d3 is based on param3d1). I see it needs matrices. The example by Rafael made that clear to me. Thanks Rafael for a very good example to work with. Best regards, Claus On Sun, Jan 28, 2018 at 5:24 PM, Rafael Guerra <[hidden email]> wrote: Hi Samuel, _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
jean-philippe grivet |
Hi Claus, Rafeal and Samuel, Here is another method for stacked plots, which was suggested to me years ago by Serge Steer.I used it succssfully for about 12 individual curves. Cheers, JP Grivet Le 28/01/2018 20:19, Claus Futtrup a
écrit :
_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users grivet.sce (316 bytes) Download Attachment |
Hi JP Thanks. Before asking in the forum I did find the grivet.sce file by Google search. To me the xfpoly solution looked like a 2D plot... I'll check your attached code again, maybe I'll have a revelation :-) Best regards Claus On Jan 31, 2018 12:16, "Jean-Philippe Grivet" <[hidden email]> wrote:
_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Samuel GOUGEON |
In reply to this post by Samuel GOUGEON
Hello,
Le 28/01/2018 à 17:16, Samuel Gougeon a écrit : Hello Rafael, A new merged and improved version of param3d() and param3d1() pages is commited and is proposed there in PDF: http://bugzilla.scilab.org/attachment.cgi?id=4621 Please tell me about any unclear statement that could be still improved. I hope that this will ease further works with 3D curves. Regards Samuel PS1: new examples scripts are also proposed:
PS2 : Beside being somewhat duplicates, the current pages have various issues: https://help.scilab.org/docs/6.0.0/en_US/param3d.html https://help.scilab.org/docs/6.0.0/en_US/param3d1.html
Quite misleading, indeed... _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
In reply to this post by Rafael Guerra
Hi Rafael I've tried to make this code work for me, but ... (code):
// START OF CODE frequencies = [201 811 3183 12862 25113]; // Hz; angles = [0 30 60 90]; // deg m_norm = [ 1.0 0.9945629 0.9643959 0.8756431; 1.0 0.9914442 1.0244046 0.9414654; 1.0 0.9910279 0.9670986 0.8932413; 1.0 0.9339808 0.8378147 0.7067978; 1.0 0.8985782 0.7536068 0.5074218]; [nf na] = size(m_norm) A = (angles .*. ones(nf,1))'; F = (frequencies .*. ones(na,1)); M = 20*log10(m_norm'); // dB scale clf(); sp = gca(); param3d1(F,A,M,alpha=50,theta= e = gce(); for i=1:nf; e.children(i).thickness = 2; end xgrid; sp.log_flags = "lnn"; // x-axis log scale (frequencies) sp.cube_scaling = "on"; xlabel("Frequency (Hz)"); ylabel("Angle (deg)"); zlabel("Mag (dB)"); // END OF CODE The above code draws lines in the Y-axis direction. What I intended to do is to draw lines in the frequency-direction (x-axis direction). I see how e.children(i) manipulates the curves, but have failed to find a way to change this (= the direction of the lines). I looked also at the examle that Samuel gave with the plot3d3, where he draws a globe and can turn lines on/off in the two directions ... I also looked at the latest proposal by Samuel to updated param3d(1) and the lines in his last examples are drawn along the x-axis direction. Is the only solution to plot angle on x-axis and frequencies on y-axis? (the rotate the cube differently) ... (it's weird how one can stare at this for days without really understanding what goes on) Best regards, Claus On Sun, Jan 28, 2018 at 4:39 PM, Rafael Guerra <[hidden email]> wrote: Claus, _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Hi Claus, On the basis of early code provided, I think you just need to transpose the matrix inputs to param3d1 in order to have the parametric curves plotted
at fixed angles along <> frequencies. See below: // START OF CODE frequencies = [201 811 3183 12862 25113]; // Hz; row vector angles = [0 30 60 90]; // off-axis angles, degrees m_norm
= [ 1.0 0.9945629
0.9643959 0.8756431;
1.0 0.9914442
1.0244046 0.9414654;
1.0 0.9910279
0.9670986 0.8932413;
1.0 0.9339808
0.8378147 0.7067978;
1.0 0.8985782
0.7536068 0.5074218]; [nf
na] = size(m_norm) A = (angles .*. ones(nf,1))'; F = (frequencies .*. ones(na,1)); M = 20*log10(m_norm'); // dB scale clf(); sp
= gca(); // Get current axis handle param3d1(F',A',M',alpha=50,theta=-110,flag=[2,4]); e =
gce() //the handle on the 3D polyline e.children.foreground
= color('dark blue'); e.children.thickness
= 2; xgrid; sp.log_flags
= "lnn"; // x-axis log scale (frequencies) sp.cube_scaling
= "on"; xlabel("Frequency
(Hz)"); ylabel("Angle
(deg)"); zlabel("Mag
(dB)"); // END OF CODE Regards, Rafael _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
In reply to this post by Claus Futtrup
Le 03/02/2018 à 18:35, Claus Futtrup a
écrit :
What I intended to do is to draw lines in the frequency-direction (x-axis direction).Claus, There are 2 distinct things: a) the law you want to plot: Z(f)_theta or Z(theta)_f b) the direction along which you want to plot the chosen law at the varying parameter The only thing that you can't choose is that param3d1() plots each line from a particular triplet of X,Y,Z columns, for all columns. Then, you can do what you want. Here is again the param3d1() example, but in an asymetric version (a long and a short sides): [X, Y] = ndgrid(-11:0.5:9, -5:0.5:6); // x is the long side, y the short one clf subplot(1,2,1) R = sqrt(X.*X + Y.*Y) + %eps; Z = sin(R)./R; param3d1(X, Y, Z, 150, 85, flag=[2,4]) subplot(1,2,2) R = sqrt(X'.*X' + Y'.*Y') + %eps; Z = sin(R)./R; param3d1(X', Y', Z, 150, 85, flag=[2,4]) Since this looks not trivial, i will change the example in the page to better illustrate both cases. Cheers Samuel _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
In reply to this post by Rafael Guerra
Hi Rafael ... "bingo" ... this is what I couldn't see. :-) Best regards, Claus On Sat, Feb 3, 2018 at 7:19 PM, Rafael Guerra <[hidden email]> wrote:
_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
In reply to this post by Samuel GOUGEON
Hi Samuel Thank you. This thing with the direction of the lines is difficult to "discover" by accident. :-) ... And thanks for the good help for param3d(1). I hope Scilab will adopt it. Best regards, Claus On Sat, Feb 3, 2018 at 8:02 PM, Samuel Gougeon <[hidden email]> wrote:
_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Le 03/02/2018 à 20:11, Claus Futtrup a
écrit :
When parts of curves are behind each others, there is a mess due to the perspective. Here is a way to avoid this (i will also add it in the page): [Xo, Yo] = ndgrid(-10:0.5:10); R = sqrt(Xo.*Xo + Yo.*Yo) + %eps; Zo = sin(R)./R; clf // Simple plot with messed curves in the perspective subplot(1, 3, 1) param3d1(Xo, Yo, Zo, 150, 85, flag=[2,4]) // With a curtain and filled curved (to avoid messed areas) subplot(1,3,2) nc = size(Xo,"c"); zmin = min(Zo); X = [Xo(1,:) ; Xo ; Xo($,:)]; Y = [Yo(1,:) ; Yo ; Yo($,:)]; Z = [zmin*ones(1,nc) ; Zo ; zmin*ones(1,nc)]; param3d1(X, Y, Z, 150, 85, flag=[2,4]) e = gce(); e.children.fill_mode = "on"; // Try to mask the curtain with %nan // => unsuccessful due to the bug http://bugzilla.scilab.org/11803 subplot(1,3,3) X = [Xo([1 1],:) ; Xo ; Xo([$ $],:)]; Y = [Yo([1 1],:) ; Yo ; Yo([$ $],:)]; Z = [[zmin ; %nan]*ones(1,nc) ; Zo ; [%nan ; zmin]*ones(1,nc)]; param3d1(X, Y, Z, 150, 85, flag=[2,4]) e = gce(); e.children.fill_mode = "on"; _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Hi Samuel You're ahead of my next questions there ... :-) ... it looks very nice. Best regards, Claus On Feb 3, 2018 21:28, "Samuel Gougeon" <[hidden email]> wrote:
_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Hi Samuel
To be able to execute your example (using Scilab 6.0.0, MS Win7) I had to provide ndgrid with two inputs: [Xo, Yo] = ndgrid(-10:0.5:10,-10:0.5:10); Cheers, Claus _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Hi Claus,
Indeed, ndgrid(x) standing for ndgrid(x,x) was not yet available in the official 6.0.0 release, while i am using the 6.0.1. It has been implemented in the meantime. Sorry for this misleading situation. Cheers Samuel Le 03/02/2018 à 23:39, Claus Futtrup a écrit :
_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Free forum by Nabble | Edit this page |