# Algebra of Graphics z-order? Controlling the plotting order

**URL:** <https://discourse.julialang.org/t/algebra-of-graphics-z-order-controlling-the-plotting-order/66112>\
**Category:** General Usage\
**Tags:** plotting, algebraofgraphics\
**Created:** [August 10, 2021, 7:19am UTC](https://discourse.julialang.org/t/algebra-of-graphics-z-order-controlling-the-plotting-order/66112 "2021-08-10T07:19:59Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [August 10, 2021, 9:52am UTC](https://discourse.julialang.org/t/algebra-of-graphics-z-order-controlling-the-plotting-order/66112/3 "2021-08-10T09:52:52Z")

</div>

There was an “optimization” that scrambled the plotting order, should be addressed by [this PR](https://github.com/JuliaPlots/AlgebraOfGraphics.jl/pull/254) (docs preview [here](http://juliaplots.org/AlgebraOfGraphics.jl/previews/PR254/)). 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
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.

---

_[View the full topic](https://discourse.julialang.org/t/algebra-of-graphics-z-order-controlling-the-plotting-order/66112)._
