I’m solving an ODE, and want to change the time axis (abscissa) to a Date – or rather: DateTime.
using Plots, Dates, DifferentialEquations
#
# test case
tust!(x,p,t) = -x/p + 2sin(t*2pi)
#
x0 = 3.
p = 0.5
tspan=(0.,10)
prob = ODEProblem(tust!,x0,tspan,p)
sol = solve(prob)
I can transform the solution by:
mymap(t,x) = (t,-2x)
plot(sol,vars=(mymap,0,1))
leading to:
I can do a “manual” plotting with dates:
function timeperiod(x::Float64)
Second(Int(floor(Second(Day(1)).value * x)))
end
#
tm = DateTime(2020,10,21) + timeperiod.(sol.t)
plot(tm,Array(sol))
leading to
However, if I try to do the following:
mymap2(t,x) = (DateTime(2020,10,21) + timeperiod(t),-2x)
#
plot(sol,vars=(mymap2,0,1))
this does not work… I get the following:
Question: how can I fix this so that I use the plotting recipe of DifferentialEquations and maintain the smoothness of the interpolation of DifferentialEquations?