# 4D plotting

**URL:** <https://discourse.julialang.org/t/4d-plotting/54138>\
**Category:** Modelling & Simulations\
**Created:** [January 28, 2021, 7:19pm UTC](https://discourse.julialang.org/t/4d-plotting/54138 "2021-01-28T19:19:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruchitha\_Kumar](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@Ruchitha\_Kumar](https://discourse.julialang.org/u/Ruchitha_Kumar)\
**Post date:** [January 28, 2021, 7:19pm UTC](https://discourse.julialang.org/t/4d-plotting/54138/1 "2021-01-28T19:19:00Z")

</div>

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

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [January 28, 2021, 7:30pm UTC](https://discourse.julialang.org/t/4d-plotting/54138/2 "2021-01-28T19:30:14Z")

</div>

I imagine you will either want to animate or apply a colormap to a 3D plot. Both should be possible with the [Makie](http://makie.juliaplots.org/stable/index.html) package. We can’t really help further than that without more information on what you are looking for.

---

<div class="post-metadata">

**Author:** ![Ruchitha\_Kumar](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@Ruchitha\_Kumar](https://discourse.julialang.org/u/Ruchitha_Kumar)\
**Post date:** [January 28, 2021, 7:33pm UTC](https://discourse.julialang.org/t/4d-plotting/54138/3 "2021-01-28T19:33:22Z")

</div>

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))

---

<div class="post-metadata">

**Author:** ![moeddel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moeddel/32/18641_2.png) [@moeddel](https://discourse.julialang.org/u/moeddel)\
**Post date:** [January 28, 2021, 8:38pm UTC](https://discourse.julialang.org/t/4d-plotting/54138/4 "2021-01-28T20:38:27Z")

</div>

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](https://docs.juliaplots.org/latest/#simple-is-beautiful)

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [January 28, 2021, 9:07pm UTC](https://discourse.julialang.org/t/4d-plotting/54138/5 "2021-01-28T21:07:02Z")

</div>

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:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/5/2538208b004e9b6126f246394efa166499351f2f.jpeg)

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

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 30, 2021, 3:03pm UTC](https://discourse.julialang.org/t/4d-plotting/54138/6 "2021-01-30T15:03:45Z")

</div>

> [@Datseris](#):
>
> how I plotted the following 4D chaotic attractor of the Lorenz96 model

Can you please post the source for the whole thing?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 30, 2021, 3:21pm UTC](https://discourse.julialang.org/t/4d-plotting/54138/7 "2021-01-30T15:21:35Z")

</div>

One Julia source for Lorenz96 seems to be right [here](https://en.wikipedia.org/wiki/Lorenz_96_model). Missing the nice spaghetti colors. Using this code, computing over `Tf = 66.0` seconds and using GR plot back-end:

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

```

 ![Lorenz96_N5_F8_roma_colors](https://global.discourse-cdn.com/julialang/original/3X/9/2/92825ab0240739e7e40c5b0309df2487d02d23b1.png)

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [January 31, 2021, 4:52pm UTC](https://discourse.julialang.org/t/4d-plotting/54138/8 "2021-01-31T16:52:03Z")

</div>

Sure, sorry that I forgot!

```julia
# %% 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.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 31, 2021, 7:03pm UTC](https://discourse.julialang.org/t/4d-plotting/54138/9 "2021-01-31T19:03:12Z")

</div>

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