How do I create a Makie recipe with keyword-argument?

Let me explain my case:

I want to create a plotting function that plots a 3D transformation by drawing x-y-z axes relative to the origin.

I’m not decided whether or not to use scatter or give it a custom name like plottransform. I’m familiar with making Makie recipes from the tutorial, but I can’t tell how to create keyword/default arguments.

For example I want to be able to do any of the following:

plottransform(tf)
plottransform(tf, size=1.0)
plottransform(tf, axiscolors=(:red, :green, :blue))
plottransform!(ax, tf, size=1.0)

etc.

Can you point me to a resource that explain how this is achieved ideomatically with Makie?

You would add your keyword arguments somewhere here as in the docs. For this I would recommend creating a full recipe - it gives you a lot more control!

That’s the same page I linked. I’ll be more clear; say I have the example recipe from that page

@recipe(MyPlot, x, y, z) do scene
    Theme(
        plot_color = :red
    )
end

Where in this bit of code do I add a kwarg, with a default value? Do I just do this:?

@recipe(MyPlot, x, y, z; color=:red) do scene
    Theme(
        plot_color = :red
    )
end

There are no example of this that I can find.

@recipe(MyPlot, x, y, z) do scene
    Theme(
        plot_color = :red # this is the default value for keyword arguments
    )
end

function Makie.plot!(p::MyPlot) 
    p.plot_color[] == :red # is red, if not passed something else by user. `[]` because its an observable
end
2 Likes