# Calling multiple user plot recipes from single recipe

**URL:** <https://discourse.julialang.org/t/calling-multiple-user-plot-recipes-from-single-recipe/122885>\
**Category:** Visualization\
**Tags:** plotting, plots, recipe\
**Created:** [November 21, 2024, 10:01am UTC](https://discourse.julialang.org/t/calling-multiple-user-plot-recipes-from-single-recipe/122885 "2024-11-21T10:01:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ickaser](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ickaser/32/28852_2.png) [@Ickaser](https://discourse.julialang.org/u/Ickaser)\
**Post date:** [November 21, 2024, 10:01am UTC](https://discourse.julialang.org/t/calling-multiple-user-plot-recipes-from-single-recipe/122885/1 "2024-11-21T10:01:55Z")

</div>

I am building a suite of Plots.jl recipes for my common visualizations, which has been very helpful–this functionality is awesome.

I’ve arrived at a point where I would like to compose multiple of my user recipes in a single plot axis. A MWE as follows:

I have two user recipes as follows (which in the real case do some more styling, etc., but this is the gist), and a type which I use for other purposes but would like to provide a recipe for.

```julia
@userplot MultiSeries
@recipe function f(ms::MultiSeries)
    time, ys... = ms.args
    for (i, y) in enumerate(ys)
        @series begin
            return time, y
        end
    end
end

@userplot endPlot
@recipe function f(tp::endPlot)
    t_end = tp.args[1]
    @series begin
        seriestype := :vline
        label --> "\$t_\\text{end}\$"
        return [t_end]
    end
end

struct SeveralData
    t
    ys
    t_end
end

s = SeveralData(1:10, [rand(10) for _ in 1:3], 12)

```

What I am hoping to do is provide a recipe as follows:

```julia
@recipe function f(s::SeveralData)
    return [MultiSeries((s.t, s.Ts...)), tendPlot(s.t_end)]
end

```

so that instead of

```julia
multiseries(s.t, s.ys...)
tendplot!(s.t_end)

```

I can simply do

```julia
plot(s)

```

As written, I get `ERROR: Cannot convert MultiSeries to series data for plotting`. Is there a change to my syntax that fixes this? Or am I going about this the wrong way?

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [November 21, 2024, 6:25pm UTC](https://discourse.julialang.org/t/calling-multiple-user-plot-recipes-from-single-recipe/122885/2 "2024-11-21T18:25:23Z")

</div>

If all you want to do is to give the last series different styling you can just do

```julia
@userplot MultiSeries
@recipe function f(ms::MultiSeries)
    time, ys... = ms.args
    for (i, y) in enumerate(ys)
        if i == length(ys)
              # do it different
        else
            @series begin
                 return time, y
            end
        end
    end
end

```

It is possible to return objects to call a different recipe, but I don’t think that works with inhomogeneous vectors like you have here.

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [November 21, 2024, 6:32pm UTC](https://discourse.julialang.org/t/calling-multiple-user-plot-recipes-from-single-recipe/122885/3 "2024-11-21T18:32:48Z")

</div>

With this example, this worked:

```julia
@recipe function f(s::SeveralData)
           @series begin
               return MultiSeries((s.t, s.ys...))
           end
           @series begin
               return endPlot(s.t_end)
           end
       end

```

---

<div class="post-metadata">

**Author:** ![Ickaser](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ickaser/32/28852_2.png) [@Ickaser](https://discourse.julialang.org/u/Ickaser)\
**Post date:** [November 21, 2024, 7:28pm UTC](https://discourse.julialang.org/t/calling-multiple-user-plot-recipes-from-single-recipe/122885/4 "2024-11-21T19:28:40Z")

</div>

That worked a treat, thanks! I spent a good half hour thinking that it was causing a mess with my styling, but it turned out I just forgot which of my recipes was which.

And for any future readers: my use case has `if` branches where it checks for `missing` data, in which case it only applies some of these series, and the recipe still handles everything great.
