Makie: Coordinates of objects in the "scene" coordinates?

This is a continuation of the thread that I link at the end of this message. There I went off topic and so I thought it’s wiser to start a new thread instead of posting further questions there.

My question is, how do you find out the locations of “axis” objects in terms of the “scene coordinates”.

In the following toy example, I plot two graphs (“Axes”) side by side and later add a horizontal line to the “scene” that marks the location of the common y origin:

using CairoMakie
fig = Figure()
ax1 = Axis(fig[1,1], limits=(nothing,(-0.3, 1.5)) )
ax2 = Axis(fig[1,2], limits=(nothing,(-0.3, 1.5)) )
xs = 0:(pi/16):(2pi)
lines!(ax1, xs, map(sin, xs))
lines!(ax2, xs, map(cos, xs))
lines!(fig.scene, [0.06, 0.98], [0.22177,0.22177]; space = :relative,
       color = RGBAf(0.5,0.5,0.5,0.5) )
save("tmp.png", fig)

In this example, I found out the location of the y axis just by trial and error, but you of course want to systematically calculate the position without trial and error.

In the past, I did this kind of trial and error many times on other plotting tools. What’s depressing about trial and error is that you have to redo the trial and error if/when you change something about the main plots. . . .

The above is just an example. There are potentially a lot of uses. For example, you might want to plot a piece of text at a certain “scene” position relative to some elements of multiple “Axes”.

An Axis shows its plot content in a separate Scene, which is in ax.scene. This Scene has a rectangular viewport area, which is in ax.scene.px_area. This rectangle gives you the location of the Axis in the Figure at any given time. It’s an observable, so you can lift other stuff off it.

1 Like

Thanks! I’ll explore that and report back in due course.