2

I recently upgraded to TeXLive 2018 and found that the behavior of the addplot fill between behaves differently now. What I'm trying to do is to fill the area between a straight line and a parabola. Before upgrading, this worked fine. Now an entirely different area is being filled in. Here's my MWE that illustrates the problem I'm having now:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
\begin{axis}[axis on top,xmin = -3.2,xmax =  3.2,ymin = -2.2,ymax =  3.2,
  axis x line = middle,axis y line = middle]

  \path[name path=line] (-3,3) -- (3,3);
  \addplot[name path=para,domain=-3:3,mark=none,samples=101] {0.25*x^2};

  \addplot[fill=blue] fill between[of=para and line,
    soft clip={(-3,0) rectangle (3,3)}];  
\end{axis}

\end{tikzpicture}
\end{document}

Here's the result:

enter image description here

What should (and did) happen is that the area above the parabola should be filled in up to y=3.

What's confusing me is that I tried using the compat option to use older versions of pgfplots but observed no changes. What is also odd is that the behavior is different depending on whether I have the \pgfplotsset{compat=newest} line commented out or not.

Am I doing something wrong that just happened to work correctly beforehand?

  • Is this the picture you get with this code? I get a very different output on my updated TeXLive 2018 distribution on MacOS when compiling with pdflatex. Which OS and compiler are you using? – user121799 Jan 13 at 19:30
  • BTW, if you only want to fill the area above the parabola, you could simply use \addplot[name path=para,domain=-3:3,mark=none,samples=101,fill=blue] {0.25*x^2} -- (3,3) -- (-3,3)-- cycle;. fillbetween is not needed for this variant. – user121799 Jan 13 at 19:35
  • @marmot: Regarding your first question, yes, this is the picture I get with this code. I'm using MacTeX on OS X 10.13.6. As I stated, I updated to TeXLive 2018 recently. I just saw that there are a couple of updates, including pgf. Let me check whether this makes a difference and get back to you. – user1362373 Jan 13 at 19:49
  • @marmot: Regarding your BTW, I just tried this and get exactly the same behavior. – user1362373 Jan 13 at 19:56
  • 1
    @user1362373 You might want to report this issue on the pgfplots bugtracker: sourceforge.net/p/pgfplots/bugs – Henri Menke Jan 14 at 9:03
4

This is a tricky one because we don't know which was your previous version of PGFPlots which resulted in your desired result (the right part of the image below). When you now get the left part of the image below with the provided code as-is then I guess you are on the one version of PGFPlots which had a bug in the compat key where newest didn't work. (I was not in the mood to track that down.)

With the current version of PGFPlots (v1.16) and your provided code you should get the middle part of the image below (This is also most likely the result @marmot gets). Some more details of how you can again get your desired result, please have a look at the comments of the code. (There are also some more/other comments which give you hints how you can also get the three parts of the image below.)

Is that good enough for you?

% used PGFPlots v1.16 (and TikZ v3.1)
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \usepgfplotslibrary{fillbetween}
    \pgfplotsset{
%        % When using this `compat` level or lower and using the second definition
%        % of the `line` path you get the desired result. ...
%        compat=1.10,
        % When using `compat=1.11` (or higher) one gets a "strange" result,
        % thus, something must have changed here which I don't want to track down.
        compat=1.11,
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis on top,
        xmin=-3.2,
        xmax=3.2,
        ymin=-2.2,
        ymax=3.2,
        axis x line=middle,
        axis y line=middle,
        domain=-3:3,
        no markers,
        samples=101,
    ]

        % This does only what you want if you use `compat=1.11` or higher,
        % because then TikZ pathes are interpreted as `axis cs:` coordinates ...
        \path [name path=line] (-3,3) -- (3,3);
%        % If you use `compat=1.10` or lower (which is also the case when not
%        % stating it at all) you have to prepend the coordinates by `axis cs:`.
%        \path [name path=line] (axis cs:-3,3) -- (axis cs:3,3);

        \addplot [name path=para] {0.25*x^2};

        \addplot [fill=blue] fill between [
            of=para and line,
            % this most likely doesn't work, because the rectangle touches
            % the `para` path at x=0.
            soft clip={(-3,0) rectangle (3,3)},
%            % Thus, changing ymin from 0 to -0.1 makes it work.
%            % (Another possibility to avoid this would be to reduce `samples`
%            %  to an even value thus no data point is at x=0, e.g. `samples=100`)
%            soft clip={(-3,-0.1) rectangle (3,3)},
%            % But the easiest solution would be to supply `domain` instead of
%            % a path directly.
%            soft clip={domain=-3:3},
        ];
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the possible results of above code

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.