How can I extract and reuse/combine subplots in Julia? Consider:
pp = plot(0:0.01:2, [sin.(0:0.01:2), cos.(0:0.01:2)], layout=(1,2));
gg = plot(0:0.01:2, [sin.(0:0.01:2).^2, cos.(0:0.01:2).^2], layout=(1,2));
Both pp and gg report length 2 and are indexable, for example like: pp[1] and gg[2] etc.
julia> typeof(pp)
Plots.Plot{Plots.GRBackend}
julia> length(pp)
2
julia> pp[2]
Subplot{2}
How can I know extract and reuse these subplots? I tried:
mixed = plot(pp[1], gg[2], layout=(1,2))
expecting that Julia would know how to put Subplot objects into a new “plot container”; but no dice.
Of course I know I can make/do:
p1 = plot(0:0.01:2, sin.(0:0.01:2)
p2 = plot(0:0.01:2, cos.(0:0.01:2)
pp = plot(p1, p2, ...)
so I have re-usable pieces; but that is not my question.
Use case: Consider the output of bodeplot. If I have multiple transfer functions whose Bode plots I have already made and I want to reuse the magnitude plot from one system (Subplot{1} in the result) and the phase plot from another system (Subplot{2} in the result) this would have been an easy way to do it.
Note: For the example use case mentioned above ControlSystems.jl does have a plotphase=true which can be supplied to the bodeplot call to just get the magnitude plot. These can then be combined as appropriate. However, I don’t see a way to get just the phase plots. This post seems related but that was posted 6 years back.