Align ticks in subplots

I have the following code:

using CairoMakie

d1 = rand(1:10, 50)
d2 = rand(1:4, 20)
d3 = rand(1:10, 10)

fig=Figure()

ax_1=Axis(fig[1, 1:2])
ax_2=Axis(fig[2, 1])
ax_3=Axis(fig[2, 2])

scatter!(ax_1, 1:50, d1)
scatter!(ax_2, 1:20, d2)
scatter!(ax_3, 1:10, d3)

fig

Is there a way I can align the xticks of ax_1 and ax_2 such that similar numbers are at the same x position? I guess this is only possible by changing the size of the whole subplot?

similar numbers are at the same x position

I assume you’re not talking about just linkxaxes!?

I’ve added colsize!(fig.layout, 1, Relative(0.45)) and now the 20 is inline in the first and second plot. So, of course I could try to approximately align them with limits and colsize but I was hoping for something more elegant.
If I add linkxaxes!(ax_1, ax_2) ax_2 has the same limits as ax_1. So no, this isn’t what I’m looking for.

use colsize!(fig.layout, 1, Auto(X)) where X is a factor vs the other Auto columns. If you make the factors mirror the limit ranges, you’ll get what you want I think

Is this what you mean?

using CairoMakie

d1 = rand(1:10, 50)
d2 = rand(1:4, 20)
d3 = rand(1:10, 10)

fig = Figure()
ax_1 = Axis(fig[1, 1:2],
    limits = (0, 50, nothing, nothing))
ax_2 = Axis(fig[2, 1],
limits = (0, 20, nothing, nothing))
ax_3 = Axis(fig[2, 2])

scatter!(ax_1, 1:50, d1)
scatter!(ax_2, 1:20, d2)
scatter!(ax_3, 1:10, d3)

colsize!(fig.layout, 1, Auto(2/5))

fig

If so, then this doesn’t work.

I still don’t know exactly what you want, a visual example would help. Also “this doesn’t work” doesn’t tell me anything I can use :slight_smile:

Alright, so I made a rough sketch:

I want the grid lines between the first plot and the second one perfectly lined up as show with the red lines. So the 20 of the first plot should be aligned to the 20 of the second one, etc.

I hope this clears things up.

What about the graph on the lower right then?

Doesn’t matter… can get squished into a different aspect ratio if that’s needed.

No I mean you only care about the ticks of the left one aligning? The right one has a different range anyway

yes, exactly

One option:

using CairoMakie

d1 = rand(1:10, 50)
d2 = rand(1:4, 20)
d3 = rand(1:10, 10)

fig = Figure()
ax_1 = Axis(fig[1, 1:2],
    limits = (0, 50, nothing, nothing))
ax_2 = Axis(fig[2, 1],
limits = (0, 20, nothing, nothing))
ax_3 = Axis(fig[2, 2])

scatter!(ax_1, 1:50, d1)
scatter!(ax_2, 1:20, d2)
scatter!(ax_3, 1:10, d3)

ax_2.width = ax_1.scene.px_area[].widths[1] / 50 * 20

fig

This will not update if you change more stuff after, though.

That looks great. Thanks @jules .
What do you mean with that this will not update if I change more stuff after?

If the limits or axis widths change then the computed width will not be correct anymore. One could probably set this up via observables but it’s not necessary if you don’t change the figure like that after setting the width.

Alright. Thanks!