What is the usage of "type recipes" in RecipesBase.jl & Plots.jl?

The signature of a normal recipe looks like

@recipe function f(data::AbstractArray{MyType})

And the “type recipes”'s signature look like:

@recipe f(::Type{MyWrapper}, mw::MyWrapper) = mw.v

What is the difference? Why don’t we just define

@recipe f(mw::MyWrapper) = mw.v

The first is a user recipe, it only affects calls with that specific signature. Try for instance plot(rand(5), MyWrapper(rand(5))). If you have a type recipe Plots will know to transform the second argument, if you only have a user recipe you will need to make a recipe for that specific signature.

2 Likes