How does the `camera` attribute of `plot` work?

I am trying to understand how the camera attribute of plots works? The documentation says

Sets the view angle (azimuthal, elevation) for 3D plots

but I fail to visualize how I can set the view angle by specifying two numbers (rather than specifying the location of the camera and the angle at which it points).

My specific use case is to visualize the trajectories of replicator dynamics, which like on the 3D simplex. I want to view the plot from a camera angle so that the 3D simplex appears like a triangle but cannot figure out which coordinates to use for the camera attribute.

Here is the code:

juia> using DifferentialEquations, Plots

julia> pyplot()

julia> V(x,A,t) = x .* ( A*x .- x'*A*x)
V (generic function with 1 method)

julia> RPS = [0 -1. 1; 1 0 -1; -1 1 0]
3×3 Array{Float64,2}:
  0.0  -1.0   1.0
  1.0   0.0  -1.0
 -1.0   1.0   0.0

julia> tspan = (0,50.)
(0, 50.0)

julia> prob = ODEProblem(V,x0,tspan,RPS)
ODEProblem with uType Array{Float64,1} and tType Float64. In-place: false
timespan: (0.0, 50.0)
u0: [0.2, 0.2, 0.6]

julia> sol = solve(prob);

julia> plot(sol, vars=(1,2,3))

julia> plot(sol, vars=(1,2,3), camera=(1,1)))

The camera attribute takes two real numbers, azimuthal and elevation. These values corresponds to Azimuth and Altitude in the following diagram.

These values are more like latitude and longitude and can take 0° to 360°, or -180° to +180°; But GR back-end seems to restrict the value from 0° to 90°.

Here is a working code for Julia 1.7 with the following packages and the outputs:

  • Plots v1.28.1
  • PyPlot v2.10.0
using DifferentialEquations
using Plots
using PyPlot

V(x,A,t) = x .* ( A*x .- x'*A*x)
RPS = [0 -1. 1; 1 0 -1; -1 1 0]
tspan = (0, 50.0)
x0 = [0.2, 0.2, 0.6]
prob = ODEProblem(V, x0, tspan, RPS)
sol = solve(prob);

gr()
anim = Animation()
for i in range(0, stop = 90, step = 1)
    p = Plots.plot(sol, vars=(1, 2, 3), camera=(i, i))
    frame(anim, p)
end
gif(anim, "gr.gif", fps=24)

pyplot()
anim = Animation()
for i in range(0, stop = 90, step = 1)
    p = Plots.plot(sol, vars=(1, 2, 3), camera=(i, i*2))
    frame(anim, p)
end
gif(anim, "pyplot.gif", fps=24)

gr
pyplot

5 Likes