This question already has an answer here:

When I plot two curves on the same graph with Pgfplots, I would like the second to be placed above the first. However, if the first has lines+points and the second only lines, then the point from the first go above the lines of the second. Here is a MWE

        \addplot[red,mark=*,line width=2pt] coordinates {(0,0) (1,1) (2,2)};
        \addplot[blue,line width=2pt] coordinates {(0.5,0) (1.5,2) (2,0)};

The output is

enter image description here

As you see, the blue lines goes above the red one, but the red point is above the blue line. I would like all that is in red to be placed below the blue.

I think I can do what I want with two axis environments overlaying, each one with one curve. But is there a solution in the same axis environment?

marked as duplicate by ferahfeza, Zarko, percusse pgfplots Aug 8 '17 at 23:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • OK, thanks to the question cited as duplicate, I managed to pass the points below the blue line. But why is there such a difference of layers for points and lines? – JPG Aug 9 '17 at 7:50
  • If I use on layer=background on the red curve, nothing changes; if I use on layer=foreground on the blue, it's good. So it seems like the points are not sensitive to the on layer option? – JPG Aug 9 '17 at 8:00
  • Okay, I found the real question duplicate with my own is not the one cited in the header, but this one: tex.stackexchange.com/questions/121579/… – JPG Aug 9 '17 at 8:20

Browse other questions tagged or ask your own question.