I am writing a function using Makie.jl for some custom plotting.
The function takes a Figure and an Axis object as arguments. Although I can safely assume that the axis is somewhere within the figure, its position could be arbitrarily complex.
For instance, the figure could contain multiple cascading GridLayouts and the axis could be a direct child of one of these nested layouts.
Is there a way to determine which GridPosition the axis has been assigned to?
Here’s a minimal example to illustrate what I’m trying to achieve:
using CairoMakie
fig = Figure()
ax_left = Axis(fig[1, 1])
ax_right = fig[1, 2] = GridLayout()
ax_top = Axis(ax_right[1, 1])
ax_bottom = Axis(ax_right[2, 1])
function get_gridpos(fig, ax)
# ...
end
get_gridpos(fig, ax_bottom) === ax_right[2, 1] # I'd like this to be true
Any help or pointers would be greatly appreciated!
Thanks a lot! The code you shared works like a charm.
I just wanted to add one more detail in case anyone else is trying to do something similar. My goal was to replace the axis with an additional GridLayout and plot some things inside it. However, when I initially tried creating the GridLayout using:
layout = gp2 = GridLayout()
as in the examples in the documentation (e.g., here), I got the following error:
Found nothing as the top parent of this GridPosition.
A GridPosition or GridSubposition needs to be connected to the top layout of a Figure, Scene or comparable object, either directly or through nested GridLayouts in order to plot into it.
After some trial and error, I got it working by defining the layout like this: