Plots.jl with PGFPlotsX adds series in the wrong order

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

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:

GR works fine:

gr()

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

Using the z_order attribute makes no difference:

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!

Unfortunately pgfplots plots markers always on top no matter what…

I have just found a magic keyword thanks to this SO post. The following works as desired:

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.

2 Likes