I know the Plot function builds plots and i know how to display them. My usecase is indeed building a Plot by combining two plots.
Imagine I create a complex layout of polar/line/scatter plots, where there are many formating arguments not easy to write each time by hand. So I encapsulate them into a function foo
returning the p1::Plot
object.
But, I’d like to quickly compare two sets of data using the same layout view - so I run the foo
function with different data and imediatelly I get second p2::Plot
object. Now, I’d like to build a third plot with exactly the same layout and formating, but presenting the p1
and p2
as two series in each subplot in the complex Plot object.
So far, I’ve used the hint above (thanks, @mkborregaard) :
p1 = plot(1:50, rand(50))
p2 = plot(1:50, 0.5*rand(50))
p3 = plot([1:50 1:50], [0.2*rand(50) 0.8*rand(50)])
using RecipesBase
function insideout(a::AbstractArray)
n = length(a[1])
b = [[a[i][t] for i=1:size(a,1)] for t=1:n]
tuple(b...)
end
@recipe f(p2::Plots.Plot) = insideout([(p2.series_list[i].d[:x], p2.series_list[i].d[:y]) for i=1:length(p2.series_list)])
plot!(p1, p2) #works
plot!(p1, p3) #works also
But this is working only for the simplest single subplot usecase. The :label is not propagated and this approach will definitely not work for the more copmplex layouts with many subplots.
I’ve used the UserRecipe from RecipesBase, but unfortunatelly this type of recipe is not well documented. How can I forward to the pipeline the series_list[i].d
dictionary? How do the user recipes work in case of complex layouts?
I think the usecase of combining two almost exact plots (difference only in data, not formating and layout) is strong, as this is the natural way one can easily compare 2 different complex outputs of a calculation. Plots should have a built-in mechanism to allow this intuitive approach.I’m willing to prepare a PR, but will definitely need some guidance on the user recipe machinery.