logo

How to Adjust Camera Position for 3D Plots in Julia 📂Julia

How to Adjust Camera Position for 3D Plots in Julia

Explanation

Unlike 2D plots such as line graphs and heatmaps, 3D plots have different appearances depending on the viewing angle. The viewpoint of a 3D plot can be set using the camera=(azimuth, altitude) option. Azimuth represents the compass direction and corresponds to the angle measured from the $xz$-plane. Altitude represents the elevation and corresponds to the angle measured from the $xy$-plane. The default value is camera=(30, 30). Drawing a spiral looks like the following:

using Plots

θ = range(0, 2π, length=100)
x = sin.(2θ)
y = cos.(2θ)
z = θ

plot(x, y, z, xlabel="x", ylabel="y", zlabel="z")

Changing the altitude from 0 degrees to 360 degrees produces,

anim = @animate for i ∈ 0:2:180
    plot(x, y, z, xlabel="x", ylabel="y", zlabel="z", camera=(30,i), title="altitude = $i")
end
gif(anim)

azimuth를 바꿔보면,

anim = @animate for i ∈ 0:2:360
    plot(x, y, z, xlabel="x", ylabel="y", zlabel="z", camera=(i,30), title="azimuth = $i")
end