# In Pgfplots, how can I prevent points from hiding lines [duplicate]

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

\documentclass[crop,tikz]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[]
\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)};
\end{axis}
\end{tikzpicture}
\end{document}


The output is

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 StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Aug 8 '17 at 23:01

• 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