Align axes to each other with Makie.jl

The ticks are not spaced well because your plots are much wider than the domain you’re sampling from. That’s because the kernel density extends farther than the extrema of the data. But you can set datalimits for that on the violin! call.

Other than that there’s nothing “linked” about this plot, it’s just manually chosen to look nice I assume.

Here’s with datalimits = extrema. Much better but you might want to control the limits exactly if you want a perfect match, right now the extrema are a little bit random given the input data.

begin
    fig = Figure();
    axis = fig[1, 1] = Axis(fig, title = "First plot",
                    xticks = (0:1:1, ["0", "1"]),
                    yticks = (0:20:80));
    axis2 = fig[1, 2] = Axis(fig, title = "Second plot",
                    xticks = (0:1:1, ["0", "1"]),
                    yticks = (0:125:500));
    violin!(axis, rand((0, 1), 500), rand(0:80, 500), color = "#92a8d1", datalimits = extrema);
    violin!(axis2, rand((0, 1), 500), rand(0:500, 500), color = "#b1cbbb", datalimits = extrema);
    fig
end

2 Likes