# Error DynamicalSystems.jl Plotting trajectories

**URL:** https://discourse.julialang.org/t/error-dynamicalsystems-jl-plotting-trajectories/100655
**Category:** Modelling & Simulations
**Tags:** question, dynamical-systems
**Created:** [June 21, 2023, 2:26pm UTC](https://discourse.julialang.org/t/error-dynamicalsystems-jl-plotting-trajectories/100655 "2023-06-21T14:26:43Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![SimonNeuroscience](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonneuroscience/32/50921_2.png) [@SimonNeuroscience](https://discourse.julialang.org/u/SimonNeuroscience)
#### Post date: [June 21, 2023, 2:26pm UTC](https://discourse.julialang.org/t/error-dynamicalsystems-jl-plotting-trajectories/100655/1 "2023-06-21T14:26:43Z")

</div>

Hello,

I am trying to follow the Intro to DynamicalSystems.jl YouTube Video from the Official Julia programming Account: [Intro to dynamical systems in Julia - YouTube](https://www.youtube.com/watch?v=13hqE_1a158)

I want to plot the trajectories of a simple deterministic Dynamical System but always get an error while I try to plot the trajectories.

The Plotting error is: Cannot convert StateSpaceSet{2, Float64} to series data for plotting

While calling tr[:,1] I should get a vector but always get an error:

ERROR: MethodError: no method matching getindex(::Tuple{StateSpaceSet{2, Float64}, StepRange{Int64, Int64}}, ::Colon, ::Int64)

Somehow I can not work with these Datset types.

Code is below

```julia
## 1) Define function of System: 
# Using a Static Vector because the System is small
h_eom(x,p, t) = SVector{2}(1.0 - p[1]*x[1]^2 + x[2], p[2]*x[1] )

## 2) State 
state = zeros(2) # Does not matter if we use Vector of SVector for the state 

## 3) Parameters
p = [1.4, 0.3] # p = [a,b] from the equations of motion

## 1-3) Are enough to make a DynamicalSystems
henon = DiscreteDynamicalSystem(h_eom, state, p )

##### Getting a trejectory
# trajectory(ds:DynamicalSystems, T [, u]; kwargs... )

##### Getting a trajectory

## Trajectory from initial condition:
tr = trajectory(henon, 10000)

##Trajectory from a different starting point:
tr2 = trajectory(henon, 10000 , 0.01rand(2))

## Plotting
figure(figsize=(6,4))
plot(tr[1][:], tr[2][:], lw=0.0, marker="o", ms=0.1, alpha=0.5)
plot(tr2[1][:], tr2[2][:], lw=0.0, marker="o", ms=0.1, alpha=0.5)
xlabel("x")
ylabel("y")

```

---

<div class="post-metadata">

### Author: ![KalelR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kalelr/32/43305_2.png) [@KalelR](https://discourse.julialang.org/u/KalelR)
#### Post date: [June 21, 2023, 2:37pm UTC](https://discourse.julialang.org/t/error-dynamicalsystems-jl-plotting-trajectories/100655/2 "2023-06-21T14:37:39Z")

</div>

Hey

The trajectory function was updated and now returns both the trajectory as a StateSpaceSet and the corresponding times points as a StepRange. The error is telling you exactly this, actually. Since you assign `tr` to both, `tr` in your code is a tuple of both a StateSpaceSet and a StepRange - these are the trajectory and the time points.

To separate the two, you can simply do:

```julia
tr, ts = trajectory(henon, 10000)

```

That should solve your problem. But just as a note, you can easily transform a StateSpaceSet into a Matrix by doing:

```julia
tr_matrix = Matrix(tr)

```

Then, the plotting interfaces should handle them fine.

---

<div class="post-metadata">

### Author: ![SimonNeuroscience](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonneuroscience/32/50921_2.png) [@SimonNeuroscience](https://discourse.julialang.org/u/SimonNeuroscience)
#### Post date: [June 21, 2023, 2:46pm UTC](https://discourse.julialang.org/t/error-dynamicalsystems-jl-plotting-trajectories/100655/3 "2023-06-21T14:46:47Z")

</div>

Thank you! That fixed all my problems.
