Graph Insets with Makie

I’m attempting to inset a colorbar into the lower left corner of this graph using the example I found at the link below.

https://lazarusa.github.io/BeautifulMakie/ScattersLines/LineWithInset/

f1 = Figure(resolution = (800,800))

ax1 = Axis(f1)
hidespines!(ax1)
ax2 = Axis(f1, bbox = BBox(100,300,100,200))

hm1 = heatmap(ax1, transpose(dfm), colormap = cgrad(["white","green"],9))

ax1.yreversed = true
ax1.yaxisposition = :right
ax1.yticks = (2:3:length(labels),axisticks₁)
ax1.yticklabelsize = 10

ax1.xaxisposition = :top
ax1.xticks = (2:3:length(labels),axisticks₁)
ax1.xticklabelsize = 10

cbar = Colorbar(ax2,hm1, vertical = false, ticks = 0:0.20:1)

f1

Produces this error:

My prior code and result works fine (but can’t get the colorbar where I’d like it).

f1 = Figure(resolution = (800,800))

#ax1 = Axis(f1)
#ax2 = Axis(f1, bbox = BBox(100,300,100,200))

ax1, hm1 = heatmap(f1[1,1], transpose(dfm), colormap = cgrad(["white","green"],9))
hidespines!(ax1)

ax1.yreversed = true
ax1.yaxisposition = :right
ax1.yticks = (2:3:length(labels),axisticks₁)
ax1.yticklabelsize = 10

ax1.xaxisposition = :top
ax1.xticks = (2:3:length(labels),axisticks₁)
ax1.xticklabelsize = 10

#cbar = Colorbar(ax2,hm1, vertical = false, ticks = 0:0.20:1)

f1

I’m wondering if the code I was modeling my visualization has some deprecated aspects to it. Haven’t been able to locate in the documentation how to use bbox to place an inset otherwise.

Thanks for any help.

Jim

use the other example, which has a colorbar inside the Axis.

https://lazarusa.github.io/BeautifulMakie/ScattersLines/LineWithInsetHeatmap/

I think this should do it:

Colorbar(fig[1,1], hmap, label = "values", height = 15, vertical = false, flipaxis = false, ticksize=15, tickalign = 1, width = Relative(3.55/4), halign = :left, valign = :bottom)

Thanks for the help - Got the colorbar in the correct position:

But can’t get the colorbar to display the color range from the visualization:

let
    fxy = convert(Matrix{Float32},transpose(Matrix(df[:,1:length(labels)])));
    
    fig = Figure(resolution = (800,800))
    ax1 = Axis(fig)

    hmap = heatmap!(ax1, fxy, colormap = cgrad(["white","green"],9))

    hidespines!(ax1)

    ax1.yreversed = true
    ax1.yaxisposition = :right
    ax1.yticks = (2:3:length(labels),axisticks₁)
    ax1.yticklabelsize = 10

    ax1.xaxisposition = :top
    ax1.xticks = (2:3:length(labels),axisticks₁)
    ax1.xticklabelsize = 10

    cbar = Colorbar(fig[1,1], hmap, label = "Relative Fitness",
        vertical = false, flipaxis = false,
        ticksize = 10, tickalign = 1, ticks = 0:0.2:1.4,
        tellheight = false, tellwidth = false,
        width = Relative(1/2), 
        halign = :left, valign = :bottom)
    
    fig[1,1] = ax1    
    fig
end

JB

Could you check if the colors are visible if the colorbar is not on the Axis? It could be that the axis background covers it somehow. Maybe you can also change the axis backgroundcolor to transparent. Otherwise you’d need to reach into the colorbar internals and translate! the color part forward in z.

Yes, when I place the colorbar into another grid position (like fig[2,1] - it displays nicely. I tried changing the background color to transparent (ax1.backgroundcolor = :transparent) without any effect.

Any recommendations on how to navigate the translate! - I understand conceptually what you are saying - but a quick look in the documentation didn’t give me a clear idea of how to navigate the internals of the colorbar to push the color up front.

Thanks for the help.

Currently layoutables have no concept of z-order, because many are just loose collections of plot objects and don’t have their own scene. So in those cases your best bet is to check obj.elements, that is usually the dict where I save those plot objects, although it’s not official API. Then you can do translate!(some_element, 0, 0, 100) for example to push an object forward. It’s clunky, but it works. Probably it would be nice to formalize a z-index for layoutables exactly for these kinds of layering scenarios.

Thanks for this. I appreciate it and the work you all have done on Makie. Looking forward to seeing this continue to evolve.

JB