There was an “optimization” that scrambled the plotting order, should be addressed by this PR (docs preview here). This way the “z-order” should follow the sorting order (smaller values get drawn first and appear first in the legend). This is the same as one would get by doing the plot directly in Makie, so it should be a reasonable default. Could you check out the PR and see if it fixes your usecase?
For more nuanced situations (say one wants to order plots and legend differently, or more complex z orderings), I’m not sure what’s the best solution. Maybe adding an explicit z_order
attribute to Makie? I imagine it would be easy to implement given that a similar machinery exists for z coordinates. OTOH, just using z coordinates doesn’t work in general for e.g. contours and more complex plots.
Btw, I’ve tried
julia> fig = Figure();
julia> ax = Axis(fig[1, 1]);
julia> scatter!(ax, rand(100), rand(100), fill(100, 100));
julia> scatter!(ax, rand(100), rand(100), fill(0, 100));
julia> fig
in CairoMakie, but I still get first trace below the second, I was expecting it to be the other way around.