Subplot enumeration for papers with Makie.jl

Hi there, I have a figure like this:

made with PyPlot. The contents of the figure do not matter, only the letters that are in the upper right corner of each axis. Such “enumeration” is critical for publication quality figures, but I am not sure how to achieve it with Makie.jl in an “automated way”. With PyPlot.jl I can actually do something simple:

"`add_identifiers!(fig = gcf(), axs = fig.get_axes(); xloc = 0.985, yloc = 0.975)`"
function add_identifiers!(fig = gcf(), axs = fig.get_axes(); xloc = 0.975, yloc = 1)
    bbox = Dict(:boxstyle => "round,pad=0.3", :facecolor=>"white", :alpha => 1.0)
    for (i, ax) in enumerate(axs)
        l = collect('a':'z')[i]
            ax.text(xloc, yloc, "$(l)"; transform = ax.transAxes,
            bbox = bbox, zorder = 99, va = "top")
        catch err
            @warn err

So after I Have created a figure with multiple subplots, I simply call add_identifiers!(fig) and it just works automatically and nicely puts the identifier letter on the top-right of the axis no matter how large the axis is, or where it is.

How to do this in Makie.jl?

I think you are looking for Label, as in:

julia> fig = Figure();

julia> ax1 = Axis(fig[1, 1]);

julia> lines!(ax1, 0..10, sin);

julia> Label(fig[1, 1, TopRight()], "(a)");

julia> ax2 = Axis(fig[2, 1]);

julia> lines!(ax2, 0..10, cos);

julia> Label(fig[2, 1, TopRight()], "(b)");

julia> fig

(Not sure if there is anything more specific for paper figures, but Label allows a fair amount of customization, so you should be able to tweak it…)

EDIT: here are the docs for Label. I’ve just realized I’m not using the default theme, but you can tweak the font of the label to make it look more “label like”, for example this one is Fira Sans with medium weight.

1 Like

The thing is, I really like the current design I have, where there is this nice box around the label. I will be putting it ontop of the axis splines, so this box is necessary to make the label distinct. I’d also like to automatically do the axis enumeration, also not sure how to loop over axis of a figure without explicitly collecting them like you did above with ax1 and ax2.

The solution so far is to use Label in the same location as the Axis.

Something like:

    GLMakie.Label(fig[i, 1], labels[i]; 
        tellwidth=false, tellheight=false,
        valign = :top, halign = :right, padding = (0, 5, 5, 0),

This requires one to know beforehand to which figure location each axis corresponds to. I’m now trying to figure out how to exact this information from an Axis instance.