OK… I think I understand the logic you present, and from that it follows that I had misunderstood what the twinx()
function does.
So, if I understand it correctly, the twinx()
creates a second axis of the previously displayed plot. And by setting yaxis2 = twinx()
, you define a “plot handle” (in MATLAB terminology) to this second axis of that plot.
It was still somewhat convoluted to add xlabel
and ylabel
for the plots… Here is the plot I finally managed to create, after quite a bit of testing:
It is not relevant here to go into too much details, but here is more or less what I had to do… [note: I also created another plot in parallel with the one included above]:
# Preparing for the figure included above ("Voltages") ...
fg_1 = plot(sol,idxs=u, xlabel="",ylabel=L"$u$ [V]", title="Voltages",
label=L"\leftarrow u", legend=:left)
fg_2 = twinx()
plot!(fg_2, sol,idxs=u_p, ylabel=L"$u_\mathrm{p}$ [V]",
label=L"u_\mathrm{p} \rightarrow", legend=:right)
# Aother figure...
fg_a = plot(sol, idxs=p,...)
# Monte Carlo simulation
Np = 20
for i in 1:Np
_u = 0.2*randn()
_k = 1 + 0.2*randn()
prob = remake(prob; u0=[u => _u], p=[k => _k])
sol = solve(prob)
plot!(fg_1 , sol, idxs=u, label="", xlabel="")
plot!(fg_2 , sol, idxs=u_p, label="", xlabel="")
plot!(fg_a,sol, idxs=p, ...)
end
plot!(fg_2, xlabel=L"$t$ [s]")
plot!(fg_1, frame=:box)
Note: if I replace the last two statements by plot!(fg_1, xlabel=L"$t$ [s]", frame=:box)
, this produces two labels on the abscissa (“x axis”). I had to add ylabel
’s prior to the for
loop in order to get them correctly placed. Etc., etc.
So: somewhat convoluted.