# Understanding plot recipes with identical arguments

**URL:** <https://discourse.julialang.org/t/understanding-plot-recipes-with-identical-arguments/67921>\
**Category:** General Usage\
**Tags:** question, plotting, recipe\
**Created:** [September 9, 2021, 9:28am UTC](https://discourse.julialang.org/t/understanding-plot-recipes-with-identical-arguments/67921 "2021-09-09T09:28:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [September 9, 2021, 9:28am UTC](https://discourse.julialang.org/t/understanding-plot-recipes-with-identical-arguments/67921/1 "2021-09-09T09:28:21Z")

</div>

I just discovered the recipes mechanism in order to avoid having `Plots` as a package dependency.

I currently have a `plot1(x::TypeX,y::TypeY)` and `plot2(x::TypeX,y::TypeY)` functions which help present the same data in a different manner. Both have their advantages and shortcomings, so I would like to keep both available.

Now that I want to switch my definitions to recipes, I figured I could replace the

```julia
function plot1(x::TypeX,y::TypeY)
    <some plotting code>
end

```

definition to

```julia
@recipe function plot1(x::TypeX,y::TypeY)
    <some equivalent recipe code>
end

```

The same goes for `plot2`.

However, given the way recipes seem to works, the way to call this recipes is not `plot1(X,Y)` and `plot2(X,Y)`, but simply `plot(X,Y)` for both, which makes one of the unavailable/overwritten.

I suppose I am not the first one to have this issue but I am confused… What is the correct way to avoid this. Using a `@userplot` maybe useful, but I do not see how it fits here.

Thanks !

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [September 10, 2021, 1:23pm UTC](https://discourse.julialang.org/t/understanding-plot-recipes-with-identical-arguments/67921/2 "2021-09-10T13:23:44Z")

</div>

Ok so I tested something with `@userplot`, which leads to

```julia
@userplot Plot1
@recipe function f(h::Plot1)
    if length(h.args) != 2 || !(typeof(h.args[1]) <: TypeX) || !(typeof(h.args[1]) <: TypeY)
        error("Wrong arguments, got $(typeof(h.args))")
    end
    <some recipe code>
end

```

Then I can call `plot1(X,Y)` as required. However, it feels weird to somewhat go around the whole multiple dispatch thing and validate the arguments afterwards. Can someone explain this approach ?
