A Figure contains a GridLayout. Label(fig[1,1],...) tells the Label to use cell (1,1) of the Figures GridLayout. I’d recommend reading through the excellent Makie tutorials:
I was reading the tutorial before. I still don’t find it logical to access array elements without creating an array (with known dimensions) in the first place. This feels like Matlab, you can never get an out-of-bounds error with this scheme, very error prone.
Probably worth a separate topic, but I never understood this choice either. I avoid the figure indexing syntax whenever possible by using AlgebraOfGraphics.jl or direct plotting methods because I get confused every time I see it. Particularly, this statement from the basic tutorial makes no intuitive sense to me:
We’ll learn more about layouts later, but for now the position f[1, 1] will just fill the whole figure.
Well the full GridLayout fills the Figure and it grows on demand. By default it contains only the cell at (1,1).
Personally I find these semantics very convenient for iteratively constructing complicated figures. E.g. if you all of the sudden want another colorbar on the left then you don’t need to shift all subplots over and can just put the colorbar in the 0th column.
Coming back to the original question: Is there an easier solution than this one if you want to display a text in a Makie window and provide the x, y position?
But again, I find it confusing. What is the difference between a Figure and a Scene? How can it be that I can use a Scene instead of a Figure? Why do I need two distinct types if they are interchangeable?
UPDATE:
Scene and Figure are actually NOT interchangeable. In this example I MUST use a Scene and cannot use a Figure. But why?
A Figure is a Scene plus a GridLayout. You could use a plain Scene for all your drawing in Makie but then you’d have to place all your elements manually where you want them. So the Figure is a Scene that has already been connected to the GridLayout in a way that the layout follows the scene size (think resizing your window in GLMakie). The Figure also has a little bit of a bookkeeping functionality as it holds a vector of Blocks which are just composites of child scenes and plots, but the underlying Scene does not know about that concept at all.
A Figure is not an array, the fig[1, 1] syntax directly forwards to fig.layout[1, 1] which is mostly more annoying to write as you’re going to do this often, and the Figure needs no other indexing behavior, so we made the choice long ago to have one mean the other.
A GridLayout is not an array. The indexing syntax was just the most ergonomic syntax to use. Indexing into it returns an object that describes a position in the layout. It doesn’t yet mutate the layout. Placing an object there by then doing Axis(fig[2, 3]) or whatever does mutate the layout. It does not have a “storage area” like a matrix so there’s no reason not to allow this. It would be very inconvenient when building figures if you had to decide at line 1 how many rows and columns you want to have. You could not make anything iteratively this way.
Blocks like Axis all are layout-aware objects based on Scenes with content that are meant to be rectangular pieces in a Figure. Plots are combinations of Makie’s visual primitives and are meant to live as children of a Scene (when you plot into an Axis you really plot into the child Scene that the Axis owns).