How to retrieve axis handle from figure object?

Hello,

I have a function that creates a Makie (CairoMakie) plot and returns its figure object.
Occasionally, I need to modify some of the figure settings (e.g. axis limits) after this function is executed and the figure object is returned to REPL, but don’t want to pass them as input arguments to this plotting function. The returned figure object may contain multiple axes and I just can’t figure out how to get the handle to a specific axis from the figure object. There must be a straightforward way to do this, right?
Thanks,
Hanshin

using GLMakie

fig = Figure()
ax = Axis(fig[1,1])
t=0:.01:1
plot!(ax, t, sin.(2π.*t))
ax=Axis(fig[2,1])
plot!(ax, t, cos.(2π.*t))

# the axes can be accessed through the content member of the figure
ylims!(fig.content[1], -3, 3)

3 Likes

Great! thank you!

Should fig.content support CartesianIndex? It is very common to update the axis at position [i,j] in a grid layout.

I’ve been wondering this for a while too. I found the answer in this video: https://www.youtube.com/watch?v=L-gyDvhjzGQ

this style allows selecting a certain plot:

ax1 = content(fig[1,1])
ax2 = content(fig[2,1])

also, need to use: contents() if there is multiple things at the figure position.

Yeah fig.content is just a way to keep track of the Blocks in the figure in the order they were created in. The layouts themselves store the arrangement and as layouts are not matrices, there’s also no matrix storage anywhere.