Hey everyone !
It’s my first topic on this forum and i’m here to ask a little question about the use of plot. I have done the following code to display a landmark in 3D. But when i call the function “affichage_R”, nothing display. I have made some research, tried some things like gui() after the plot but still nothing. Do u have any ideas?
Kind Regards,
Dailysight
using Plots
l = 1;
function affichage_R(Tc, l)
x=zeros(3);
y=zeros(3);
z=zeros(3);
P=Tc[1:3,4];
P1=Tc[1:3,4]+Tc[1:3,1]*l;#Pour Sc
P2=Tc[1:3,4]+Tc[1:3,2]*l;#Pour Nc
P3=Tc[1:3,4]+Tc[1:3,3]*l;#Pour Ac
#Affichage Sc
x[1]=P[1];
x[2]=P1[1];
y[1]=P[2];
y[2]=P1[2];
z[1]=P[3];
z[2]=P1[3];
plot3d(x,y,z)
gui()
#Affichage Nc
x[1]=P[1];
x[2]=P2[1];
y[1]=P[2];
y[2]=P2[2];
z[1]=P[3];
z[2]=P2[3];
plot3d!(x,y,z)
#Affichage Ac
x[1]=P[1];
x[2]=P3[1];
y[1]=P[2];
y[2]=P3[2];
z[1]=P[3];
z[2]=P3[3];
plot3d!(x,y,z)
end
affichage_R(T01,l)
Hi! Welcome to Julia’s discourse forum!
The problem in here is that you need to either return the plot object from the function, or to call display() before. This is done automatically when you call plot directly in the REPL (and not inside a function).
example:
using Plots; gr()
function plotsomething()
p1 = plot(rand(10))
1+1 # doing something else
return p1
end
or calling display inside
using Plots; gr()
function plotsomething()
p1 = plot(rand(10))
1+1 # doing something else
display(p1)
sleep(10)
end
You can read about it in the documentation, which says:
Now that you’re making useful plots, go ahead and add these plotting commands to a script. Now call the script… and the plot doesn’t show up? This is because Julia in interactive use calls display
on every variable that is returned by a command without a ;
. Thus in each case above, the interactive usage was automatically calling display
on the returned plot objects.
In a script, Julia does not do automatic displays (which is why ;
is not necessary). However, if we would like to display our plots in a script, this means we just need to add the display
call. For example:
display(plot(x, y))
If we have a plot object p
, we can do display(p)
at any time.
3 Likes
Oh i understand ! Seems logic after all !
Thank you to unlock me
Kind Regards