Change z order/index in Plots.jl

Is there a way to change the order in which plots are drawn in Plots.jl? (z index or z order in other suites)

For example

plot(rand(5))           // unfilled
plot!(2rand(5); fill=0) // filled

I would like to show unfilled above filled without changing the order of the plotting commands (one reason is that for consistency reasons I do not want to change the colors of the objects and want to use the standard colors)

Create the plots as

p1 = plot(rand(5))
p2 = plot(2rand(5), fill=0)

Compose them later in whatever order you want them to appear.

Not exactly what you asked for, but you can do

julia> plot(2rand(5); fill=0, color=2)

julia> plot!(rand(5); color=1)
1 Like

not sure how to compose plotting objects p1 and p2 onto single subplots later on, only to layouts…

thx, the color parameter almost does it

At the moment I have like ten series in one graph and it helps that each of them is at the same position for each graph. Also I’d like to not change to order of the legend. So it would be nice to not need to change the order of plotting commands but yeah, the color parameter almost does it

Looks like it’s not as simple as I seemed to remember. Reordering your plot! calls is probably simpler. Note that you don’t have to change the order the legend is displayed (it will be displayed in the order of the elements in the labels keyword argument).

1 Like