MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.42k stars 313 forks source link

Should there be a title! function? #513

Closed jagot closed 3 years ago

jagot commented 5 years ago

With the help of @asinghvi17 I got this working, which allows me to do simple subplots:

using Makie

function mfigure(f::Function, args...; kwargs...)
    scene = Scene(args...; kwargs...)
    f(scene)
    scene # This prevents `title` from showing up, but without it, subplots don't work
end

function msubplot(f::Function, scene::Scene, m, n, i; kwargs...)
    ir = lift(scene.px_area) do parent
        x,y = parent.origin
        w,h = parent.widths
        sw = max(1, floor(Int, w/n))
        sh = max(1, floor(Int, h/m))
        I = (2i - 1) >> 2
        J = rem(i-1,2)
        IRect(x+J*sw, y+I*sh, sw, sh)
    end
    subscene = Scene(AbstractPlotting.root(scene), ir)
    f(subscene)
    subscene
end

However, I can't get titles to show up, since they don't modify the scene (?):

mfigure() do scene
    lines!(scene, rand(100), rand(100))
    title(scene, "My title")
end
image

Furthermore, if I try to add titles to subplots, things go really bananas:

mfigure() do scene
    msubplot(scene, 1,2,1) do subscene
        lines!(subscene, rand(100), rand(100))
        title(subscene, "My title")
    end
    msubplot(scene, 1,2,2) do subscene
        lines!(subscene, rand(100), rand(100), color=:red)
        title(subscene, "My next title")
    end
end
image

Without titles, at least the subplots show up fine:

image
asinghvi17 commented 5 years ago

With the way we've implemented titles now, it's basically a hack. We vbox two scenes to each other, so that there's a "title scene" above the original.

asinghvi17 commented 4 years ago

This will be fixed in MakieLayout!

asinghvi17 commented 4 years ago

I had no idea this existed, but there is a title field in Axis2D (?!) which looks like this:

sc = lines(rand(10))
sc[Axis].names.title = "A title"
Screen Shot 2020-04-01 at 2 46 53  45400PM
SimonDanisch commented 4 years ago

Yeah, I secretly brought this back at some point :D

ffreyer commented 3 years ago

Axis and Axis3 have titles now, and in general you can add a Label above an axis or LScene in a figure.