Plotting to multiple separate figures

Hi. I would like to generate 2 separate figures. These are shown below. Figure 1 shows the numerical solution, plus the actual solution. Figure 2 shows the (tiny) error. I can’t put all this on a single plot since the “solution error” is about 10^-8 x smaller than the solution. There is a similar posting (Plotting multiple figures using Plots,jl), But I have “plot” and “plot!” in figure 1.

using Plots
# figure 1
plot(sol, seriestype=:scatter, title = "Solution to the linear ODE",
    xaxis = "Time (t)", yaxis = "u(t) (in μm)", label = "Numerical soln",mc=:red, ms=5)
plot!(t1, sol_act, label="Actual",lc=:black, lw=2)
# figure 2
plot(t1, err, title = "Solution Error",seriestype=:scatter, label="errors",mc=:green, ms=6)

You can add reuse = false in the argument of the second plot function.

Hi Maucejo. Thanks very much. I could not get reuse=false to do anything. However … I did a google search for “reuse=false” and found this:

I used this as a starting point, copied their code, and went though many modification/testing cycles. And, I eventually came up with this solution:

using Plots
pt1 = plot(sol,seriestype=:scatter, title = "Fig 1. Solution to the linear ODE", xaxis = "Time (t)", yaxis = "u(t) (in μm)", label = "Numerical soln",mc=:red, ms=5)
plot!(pt1,t1, sol_act,label="Actual",lc=:black, lw=2)
plot(t1, err, title = "Fig 2. Solution Error",seriestype=:scatter, label="errors",mc=:green, ms=5)

I am very new to Julia. I am borrowing heavily from the work of others. I would greatly appreciate any comments.

Thanks very much

Glad you find a working solution. I forgot to mention that reuse = false doesn’t work with the GR backend at the moment. That is why, this solution doesn’t work, since GR is the default backend.

You could save a little typing for your second plot as follows:

scatter(t1, err, title = "Fig 2. Solution Error", label="errors", mc=:green, ms=5)

Thanks very much. I am just getting into Julia. I have managed to get a numerical solution to a 2nd order nonlinear ODE problem (which bombed in Python).

1 Like