In Plots.jl, I can make a plot and then use it either as a stand-alone figure or as a subplot:
using Plots
myplot(n) = plot(1 : n; xlabel = "x")
f1 = myplot(10);
f2 = myplot(20);
fig = plot(f1, f2);
Can I do something similar in Makie.jl?
I can, of course, define
function myplot(n)
fig = Figure();
ax = fig[1,1] = Axis(fig; xlabel = "x");
myplot!(ax, n);
return fig
end
function myplot!(ax, n)
lines!(ax, 1:n);
end
But I am hoping for a less verbose solution where I don’t have to define two functions for each type of plot that I want to generate. How can I do this?
Is it a plot like a combination of basic plot types? If so, use the recipe macro to define a new recipe which will have all the axis and figure generating convenience methods. Or is this supposed to be something that generates multiple subplots already?
They are not basic plots. To give context, I simulate a model and report statistics that are grouped in certain ways.
So I have a function that plots a statistic grouped by, say, (:a, :b). There are customizations that are specific to (:a, :b).
This is called in various places and sometimes combined into subplots and sometimes not.
What I often do currently, because we don’t have subplot level recipes yet, is to make a function that receives either a Figure or a FigurePosition. If there’s no input argument, a new figure is created. This then works for both the single figure and subplot case.
function myplot(f = Figure())
Axis(f[1, 1])
Colorbar(f[1, 2])
f
end
myplot()
myplot(some_figure[1:2, 3])