2

enter image description hereI have a problem on pgfplots with "fill between". In particular, the filled area covers the axes; see attached figure. What puzzles me is that I tested the same code on a different machine and everything looks good. Both are Macbook pro and with last version of GNUPLOT installed. Code is below. Thanks!

\documentclass{article}[![enter image description here][1]][1]
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.14}% current version is 1.15
\usepgfplotslibrary{fillbetween}
\usepackage{tikz}
\pagestyle{empty}

{\begin{tikzpicture}[scale=1]
    \begin{axis}[
    axis x line=center,
    axis y line=center,
    xlabel={$x_{p1}$},
    ylabel={$x_{p2}$},
    axis line style= ultra thick,
    label style={font=\large},
      title style={yshift=1ex},
      xmin=-2,
      xmax=2,
      ymin=-2,
      ymax=2,
    title={$u=M$},
    view={0}{90},
    axis background/.style={fill=white},
        ]        
    \path[name path=axis] (axis cs:0,5) -- (axis cs:5,5);
    \path[name path=axis2] (axis cs:-5,5) -- (axis cs:0,5);
    \path[name path=axis3] (axis cs:-5,-5) -- (axis cs:0,-5);
    \path[name path=axis4] (axis cs:-5,-5) -- (axis cs:0,-5);
    \addplot[name path=A1, black,domain=-2:0,ultra thin] 
                    (-1/2*abs(x)*x,x);
    \addplot[name path=A2, black,domain=0:2,ultra thin] 
                    (-1/2*abs(x)*x,x);      
    \addplot[name path=B1, black,domain=-1.8:0,ultra thin] 
                (-1/(2-0.5)*abs(x)*x,x);
    \addplot[green!10] fill between[of=A1 and B1, on layer=axis foreground];    

    \addplot[black!30] fill between[of=B1 and axis];              
    \end{axis}
    \end{tikzpicture}

 \end{document}
2

With axis on top they come back.

\documentclass{article}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=1.14}% current version is 1.15
\usepgfplotslibrary{fillbetween}
\usepackage{tikz}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[scale=1]
    \begin{axis}[axis on top,
    axis x line=center,
    axis y line=center,
    xlabel={$x_{p1}$},
    ylabel={$x_{p2}$},
    axis line style= ultra thick,
    label style={font=\large},
      title style={yshift=1ex},
      xmin=-2,
      xmax=2,
      ymin=-2,
      ymax=2,
    title={$u=M$},
    view={0}{90},
    axis background/.style={fill=white},
        ]        
    \path[name path=axis] (axis cs:0,5) -- (axis cs:5,5);
    \path[name path=axis2] (axis cs:-5,5) -- (axis cs:0,5);
    \path[name path=axis3] (axis cs:-5,-5) -- (axis cs:0,-5);
    \path[name path=axis4] (axis cs:-5,-5) -- (axis cs:0,-5);
    \addplot[name path=A1, black,domain=-2:0,ultra thin] 
                    (-1/2*abs(x)*x,x);
    \addplot[name path=A2, black,domain=0:2,ultra thin] 
                    (-1/2*abs(x)*x,x);      
    \addplot[name path=B1, black,domain=-1.8:0,ultra thin] 
                (-1/(2-0.5)*abs(x)*x,x);
    \addplot[green!10] fill between[of=A1 and B1, on layer=axis foreground];    

    \addplot[black!30] fill between[of=B1 and axis];              
    \end{axis}
    \end{tikzpicture}

 \end{document}

enter image description here

  • Awesome, thanks! Now it works great. I wonder why this problem only occurs on a machine. I will try to figure this out. – francesco Aug 30 '18 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.