# Plots.jl with PGFPlotsX adds series in the wrong order

**URL:** <https://discourse.julialang.org/t/plots-jl-with-pgfplotsx-adds-series-in-the-wrong-order/85896>\
**Category:** Visualization\
**Tags:** question, plotting, pgfplotsx\
**Created:** [August 17, 2022, 8:57pm UTC](https://discourse.julialang.org/t/plots-jl-with-pgfplotsx-adds-series-in-the-wrong-order/85896 "2022-08-17T20:57:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joseph\_Bradley](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@Joseph\_Bradley](https://discourse.julialang.org/u/Joseph_Bradley)\
**Post date:** [August 17, 2022, 8:57pm UTC](https://discourse.julialang.org/t/plots-jl-with-pgfplotsx-adds-series-in-the-wrong-order/85896/1 "2022-08-17T20:57:25Z")

</div>

In Plots.jl, the PGFPlotsX backend won’t let me add another series with proper control over the z-order. Here is the MWE:

```julia
using Plots
pgfplotsx()

input = range(0, 4π, 100)
output = cos.(input)

plt = scatter(input, output, label = "data")
plot!(plt, input, output, label = "theory")

```

This puts the `theory` series behind the `data` series, when it should be the other way around:

 ![Screenshot 2022-08-17 at 16.54.05](https://global.discourse-cdn.com/julialang/original/3X/7/d/7d01c8548d3d344ee4f9514f2a81a7391e211a81.png)

GR works fine:

```julia
gr()

plt = scatter(input, output, label = "data")
plot!(plt, input, output, label = "theory")

```

 ![Screenshot 2022-08-17 at 16.55.19](https://global.discourse-cdn.com/julialang/original/3X/4/6/461ff0014f210af87ebfb09fc82966893b77cdbc.png)

Using the `z_order` attribute makes no difference:

```julia
pgfplotsx()
plt = scatter(input, output, label = "data", z_order = 1)
plot!(plt, input, output, label = "theory", z_order = 2)

```

Does anyone have any suggestions? I am not familiar with the PGF interface at all so I can’t find a way of using PGFPlotsX directly, but would appreciate a pointer.

Many thanks!

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [August 17, 2022, 9:05pm UTC](https://discourse.julialang.org/t/plots-jl-with-pgfplotsx-adds-series-in-the-wrong-order/85896/2 "2022-08-17T21:05:38Z")

</div>

Unfortunately pgfplots plots markers always on top no matter what…

---

<div class="post-metadata">

**Author:** ![Joseph\_Bradley](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@Joseph\_Bradley](https://discourse.julialang.org/u/Joseph_Bradley)\
**Post date:** [August 17, 2022, 9:23pm UTC](https://discourse.julialang.org/t/plots-jl-with-pgfplotsx-adds-series-in-the-wrong-order/85896/3 "2022-08-17T21:23:17Z")

</div>

I have just found a magic keyword thanks to [this](https://tex.stackexchange.com/questions/121579/pgfplots-markers-and-lines-on-different-layers) SO post. The following works as desired:

```julia
plt = scatter(input, output, label = "data", clip_mode = "individual")
plot!(plt, input, output, label = "theory")

```

The `clip_mode` argument has to be passed to the first call in order to work.
