How to plot a line in 3D using Plots.jl?

How to plot a line in a 3D axis?

Say, I want a parabola in the xy-plane (z=0)
The straightforward options do not work;

This one results an empty canvas [-1, 1] x [-1, 1]:

using Plots
xs = -5:1:5
plot(xs, xs.^2, 0)

This one produces a 2D plot:

using Plots
xs = -5:1:5
plot(xs, xs.^2, [0])

For a different plane, the code throws an error:

using Plots
xs = -5:1:5
plot(xs, [0], xs.^2)

BoundsError: attempt to access 1-element Vector{Float64} at index [1:11]

(Why is it even trying to access 11 elements of a vector which has only 1 element?)

See it as a line in a 3D space (x(s),y(s),z(s)) where s allows to go along the curve, for example the index of the vectors x,y,z

using Plots
xs = -5:1:5
plot(xs, zeros(size(xs)),xs.^2)

Thanks!

Also, does xs, zeros(size(xs)) mean that plot() can only plot in 3D in “square” domains, where the dimensions of xs and ys match?

xs and ys must have the same number of elements in the discrete space (same vector size), but their range in the physical domain can be anything: the axes are clearly not those of a square

using Plots
xs = -5:1:5
plot(xs, xs.^2,zeros(size(xs)))
1 Like

Which means one cannot have an arbitrary domain and resolution, which is not obvious.

What do you mean by

Resolution just depends on how many values you use and the arbitrary domain just depends on the values of the positions. So what it the exact problem you think there is ?

I mean that if I want to plot on [0, 1]x[0, 100] with the same 0.1 step (“resolution”), I won’t be able to, because the vectors will have different number of elements.

That is really confusing. A line in 3D is made of N points, each of them with 3 components. You can control the density of points along the line, but not along X and Y independently. Perhaps you meant a surface in 3D, where the sampling along X and Y can be defined independently?

Yeah, this makes more sense.