FillBetween library sometimes works and sometimes does not

That is a bug in the intersections library of tikz/pgf as can be seen in the following minimal example.

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{intersections}
\pgfplotsset{compat = newest}

\begin{document}

\begin{tikzpicture}[font=\normalsize]
        \gdef\softclippath{(axis cs:5,-1000) rectangle (axis cs:6,30000)}
        \begin{axis}[
            axis lines*=left, 
            xlabel={x}, ylabel = {y},
            xmin=2,
            xmax=12.5,
            ymin=-10000,
            ymax = 30000
        ]
        \addplot+[color=green, mark=none, name path=B]  table {dummy.data};

        \draw[name path=softclippath] \softclippath;
        \node[draw,fill=white,name intersections={of=B and softclippath}] at (rel axis cs:0.5,0.5) 
            {\pgfintersectionsolutions};
    \end{axis}

\end{tikzpicture}
\end{document}

enter image description here

The example does not contain any fillbetween code, but it does a sub-operation, namely to compute the intersections of the soft clip path with the input path. The \node shows the number of intersections. For some reason, that is 0 . If you restore xmax=12, you get 2.

I will take care of that bug.


There are 1425 points between x=0.012 and x=18.99867 in the dummy.data. It seems that there is a limitation for the number of points used in the plot if the path should be saved.

If I use only every second point (each nth point=2) it works for me over the whole range from xmin=0 to xmax=20.

enter image description here

\documentclass[margin=5pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween, decorations.softclip}
\pgfplotsset{compat = newest}

\begin{document}

\begin{tikzpicture}[font=\normalsize]
  \begin{axis}[
    axis lines*=left, 
    xlabel={x}, ylabel = {y},
    xmin=0,
    xmax=20,
    ymin=-10000,
    ymax = 30000,
    each nth point=2, % use only every second point
  ]
    \addplot+[color=green, mark=none, name path=B]  table {dummy.data};
    \path[name path=D] (axis cs:4,0) -- (axis cs:9,0);
    \draw (axis cs:4,0) -- (axis cs:9,0);
    \addplot[color=blue!10] fill between[of=D and B,
    soft clip={(axis cs:5,-1000) rectangle (axis cs:6,30000)}];
    %soft clip={domain=4.3:9.5}];
  \end{axis}
\end{tikzpicture}
\end{document}