CairoMakie Text Box

And here is one way (probably not the most optimal one though) to get a box with outline and color into the plot

using CairoMakie, Printf

begin
    # these will be coming from some results struct like
    # (; param1, param2, param3) = my_run_result
    param1 = 1
    param2 = "param"
    param3 = 0.5

    x = LinRange(-1, 1, 100)
    y = x .^ 3

    fig, ax, ln = lines(x, y, label="Plot 1")
    axislegend(position=:lt)
    fmt = "Param 1 = %d \n Param 2 = %s \n Param 3 = %.2e"
    gl = GridLayout(fig[1,1],
                    tellwidth = false, tellheight = false,
                    halign = :center, valign = :top)
    box = Box(gl[1, 1], color = (:orange,0.5), strokecolor = :black)
    lbl = Label(gl[1, 1], Printf.format(Printf.Format(fmt), param1, param2, param3), padding = (10, 10, 20, 20))
    # optionally: bring box and label in front of axis ticks
    # translate!(box.blockscene, (0,0,100))
    # translate!(lbl.blockscene, (0,0,100))

    fig
end

1 Like