4D plotting

How to plot a 4D graph in julia? Can someone please help with this?

Thanks in advance

I imagine you will either want to animate or apply a colormap to a 3D plot. Both should be possible with the Makie package. We can’t really help further than that without more information on what you are looking for.

5 Likes

I want to plot the hyperchaotic attractor solution to the 4D Rössler system.

following is the code:

using ModelingToolkit

rosslerattractor = @ode_def begin # define the system
dx = - y - z
dy = x + 0.25 * y + w
dz = 3 + x * z
dw = 0.5 * w - 0.05 * z
end a b c d

u₀ = [0.1; 0.1; 0.1; 0.1] # initial conditions
tspan = (0.0,100.0) # timespan
p = [0.25,3,0.5,0.0] # parameters
prob = ODEProblem(rosslerattractor, u₀, tspan, p) # define the problem
sol = solve(prob) # solve it
plot(sol, vars = (1, 2))

If you interpret one variable, you might be able to use the animation example from the Plots package.

https://docs.juliaplots.org/latest/#simple-is-beautiful

Here is my suggestion for plotting 4D chaotic attractors. You take the first 3 variables and plot them as coordinates of the 3D plot. The 4th variable you use it to color the trajectory.

For example, this is how I plotted the following 4D chaotic attractor of the Lorenz96 model:

(in Makie.jl with GLMakie.jl as a backend)

14 Likes

Can you please post the source for the whole thing?

1 Like

One Julia source for Lorenz96 seems to be right here. Missing the nice spaghetti colors. Using this code, computing over Tf = 66.0 seconds and using GR plot back-end:

plot(x,y,z, line_z = w, background=RGB(0,0,0), c=:roma, framestyle=:none,
     axis=nothing, lw = 1, label=false, dpi=600)

4 Likes

Sure, sorry that I forgot!

# %% Lorenz96 with 4th coordinate colorplotted
using DynamicalSystems, GLMakie
lo = Systems.lorenz96(4; F = 16.0)
tr = trajectory(lo, 10000.0; dt = 0.01, Ttr = 100.0)
a,b,c,d = columns(tr)

sc = Scene(; backgroundcolor = RGBf0(0.0, 0.0, 0.0))
display(sc)
GLMakie.lines!(sc, a,b,c; color = d, colormap = :tokyo, linewidth = 2.0)

sc[GLMakie.Axis].showaxis = (false, false, false)
sc[GLMakie.Axis].showgrid = (false, false, false)
sc[GLMakie.Axis].ticks.textsize = (0, 0, 0)
display(sc)

This was written before the merge Makie+MakieLayout, so maybe something is slightly off based on current Makie.jl status.

5 Likes

@Datseris, fyi your recipe parameters above seem to produce a lot less spaghetti than displayed in your original plot. :slight_smile: Decreasing the transient parameter Ttr to zero improves a lot but still not the same thing.