Makie - Defining legend output for a makie recipe

Hi, I have a makie recipe that essentially makes a stacked line graph using the band function. A very simplified example of what this looks like is this:

function Makie.plot!(myplot::MyPlot)
    band!(myplot,myplot.x,0,myplot.y1,color=:red, label = "y1")
    band!(myplot,myplot.x,myplot.y1,myplot.y2,color=:blue, label = "y2")
    band!(myplot,myplot.x,myplot.y2,myplot.y3,color=:green, label = "y3")
end

I want to make a legend that shows the color of each of these bands with their label but I seem unable to do so. Instead, when I try to add a legend, I get the warning: ERROR: There are no plots with labels in the given axis that can be put in the legend. Supply labels to plotting functions like `plot(args...; label = "My label")`

I tried to play around with legendelements but I was pretty lost on how to make it do what I am trying to do or even if that is the appropriate function to use. Any advice on this would be greatly appreciated

I don’t think it was intended as public API, given that the name is not very descriptive, but there’s this internal function that for example series overloads to return its child plots for the legend gathering:

function Makie.get_plots(plot::Series)
    return plot.plots
end

Redefining this function for my plot type worked perfectly, thank you!