# Plotting differential equations solutions with varying color

**URL:** <https://discourse.julialang.org/t/plotting-differential-equations-solutions-with-varying-color/50884>\
**Category:** Visualization\
**Tags:** plotting, diffeq, ode\
**Created:** [November 28, 2020, 12:56am UTC](https://discourse.julialang.org/t/plotting-differential-equations-solutions-with-varying-color/50884 "2020-11-28T00:56:25Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [November 28, 2020, 12:56am UTC](https://discourse.julialang.org/t/plotting-differential-equations-solutions-with-varying-color/50884/1 "2020-11-28T00:56:25Z")

</div>

When plotting **DifferentialEquations** solutions, the _plotdensity_ keyword does not seem to work together with _line\_z_. See code below where data interpolation within **Plots** does not take place, when we color the solution by the simulation time array (`line_z=sol0.t`):

```julia
using DifferentialEquations, ParameterizedFunctions, Plots
lorenz = @ode_def begin           
    dx = σ*(y - x); dy = x*(ρ - z) - y; dz = x*y - β*z
 end σ ρ β
u0=[1.,1.,1.]; tspan=(0.,60.); p=[10.,28.,8/3];
prob = ODEProblem(lorenz, u0, tspan, p) 
sol0 = solve(prob, reltol=1e-9) 
# plot(sol0, vars = (1, 2, 3)) # display interpolation is on but line_z not working with this syntax
plot((sol0[1,:],sol0[2,:],sol0[3,:]), line_z=sol0.t, plotdensity=10_000, color=:redsblues)

```

![ODE_line_varying_color](https://global.discourse-cdn.com/julialang/original/3X/2/c/2cc4beaf7eef2ed352ff06713b1e57c744edb874.jpeg)

Is this possible to do using Plots?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [November 28, 2020, 4:00am UTC](https://discourse.julialang.org/t/plotting-differential-equations-solutions-with-varying-color/50884/2 "2020-11-28T04:00:41Z")

</div>

> [@rafael.guerra](#):
>
> `plot((sol0[1,:],sol0[2,:],sol0[3,:]), line_z=sol0.t, plotdensity=10_000, color=:redsblues)`

This is not using the recipe since you explicitly told it what arrays you wanted to plot.

> [@rafael.guerra](#):
>
> `plot(sol0, vars = (1, 2, 3)) # display interpolation is on but line_z not working with this syntax`

If you did `line_z = sol0.t`, well, that isn’t going to be the right length array since it needs to match the interpolation length.

The workaround is to manually interpolate and plot. But open an issue. What we will need to handle is `line_z = 0` and then it would need to build the array in the recipe itself.
