How to add captions in Makie?

Hello guys,

I am just wondering how to add captions to figures in Makie, as highlighted in the following picture in red? I tried annotations() and text() but the effect are not satisfactory. Maybe I used them in a wrong way. Anyone may help me out? Thanks!

This is a job for the document generator like LaTeX or Franklin.jl, not Makie.

You can put a big block of text into a Figure with Label, but it doesn’t have text styling beyond a single font.

We can use Unicode bold math letters :slight_smile:

f = Figure(resolution=(300, 200))
scatter(f[1,1], rand(5))
Label(f[2,1], "π—™π—Άπ—΄π˜‚π—Ώπ—² 𝟭  A few random values")
f

image

How could we do that using text!() ? I wrote the following code under Julia 1.7.0 and
CairoMakie 0.6.6,the text is always in the plotting area.

using CairoMakie
CairoMakie.activate!()

function text_as_caption()
    lines(1:0.1:10, sin.(1:0.1:10))
    text!("This is caption.", position = (0, -10))
    current_figure()
end

text_as_caption()

Thanks! This is cool!

I still have 2 more questions:

  1. how to make Figure 1 to be bold face?
  2. if I want the caption to be left-aligned, how could I do that? I tried in the following code under Julia 1.7.0 and CairoMakie 0.6.6, but the result is weird.
using CairoMakie
CairoMakie.activate!()

function text_as_caption()
    fig = Figure(resolution = (600, 600))
    lines(fig[1,1],1:0.1:10, sin.(1:0.1:10))
    Label(fig[2,1, TopLeft()], "This is a caption.",
        tellheight = true)
    current_figure()
end

text_as_caption()
  1. You can use a website such as Bold and Italic Unicode Text Tool - 𝐁𝐨π₯𝐝 𝒂𝒏𝒅 π‘–π‘‘π‘Žπ‘™π‘–π‘π‘  to easily get bold text that you can copy-paste in your Julia program.

  2. You can use something like this:

    f = Figure(resolution=(300, 200))
    scatter(f[1,1], rand(5))
    Label(f[2,1], "π—™π—Άπ—΄π˜‚π—Ώπ—² 𝟭  Some data.", tellwidth=false, halign=:left)
    f
    

    image

    If you want the text aligned with the left of the y tick labels, I don’t know how to do that but maybe @jules has an idea you can use alignmode as described in the manual:

    f = Figure(resolution=(300, 200))
    scatter(f[1,1], rand(5), axis=(; alignmode=Outside()))
    Label(f[2,1], "π—™π—Άπ—΄π˜‚π—Ώπ—² 𝟭  Random data.", tellwidth=false, halign=:left)
    f
    

    image

    (I’m starting to think that Makie’s layouting capabilities are really awesome.)

there’s Zalgo.jl as well. :sunglasses:

1 Like

Ah nice! but it seems it doesn’t support digits, e.g. boldsans("Figure 1") returns
"π—™π—Άπ—΄π˜‚π—Ώπ—² " ?

Oh, good point. I will add them in the next release.

1 Like

Many thanks! it works fine for me :grinning:

I found Makie’s document is comprehensive but lack of organization with many details spattering around everywhere…

Always good to make an issue if you don’t find something! It grows kind of organically, so sometimes the structure needs to be refactored