# Cannot use fill between and clip markers

In the groupplot environment I need to use fill between two paths and one of these path have markers that are on the axes. I want to clip these markers but it causes a problem with fill between, as the first path is then considered as empty.

How can I clip markers and use fill between?

A MWE is given below. To see the problem clearly, you can toggle the commented line clip marker paths=true, on and off. If it is uncommented, the problem is here.

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, pgfplots.groupplots}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\begin{document}
\begin{tikzpicture}

\begin{groupplot}[group style={group size=2 by 1}, scale only axis,
%   clip marker paths=true,
axis on top=true]

% Plot main figure (a)
\nextgroupplot[scale only axis,
xmin=0,
xmax=100,
ymin=0,
ymax=550]

\addplot[name path = pathA, color=blue, mark=square*] coordinates {(0,250)(100,450)};
\path[name path = pathAxis] (axis cs:0,0) -- (axis cs:100,0);
\addplot [gray!30] fill between[of = pathA and pathAxis, soft clip = {domain=20:50}];

\nextgroupplot[scale only axis, restrict y to domain=190:240]

\end{groupplot}

\end{tikzpicture}
\end{document}

• As a workaround, you could just add a path only for the fill \addplot[name path = pathA,draw=none,no marks,forget plot] coordinates {(0,250)(100,450)}; and one for the marks and plot, \addplot[color=blue, mark=square*] coordinates {(0,250)(100,450)};. – Schrödinger's cat Dec 6 '19 at 15:09
• Your solution works perfectly for my purpose! – JuCa Dec 6 '19 at 15:17

This is only a work around. You add the plot twice, once invisibly to have something that can be used for the fill, and once "for real". (I have experimented a bit with clips and so on, but none of what popped up was really more elegant than this work around, so I post it. Obviously I do hope that there is a more elegant solution.)

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, pgfplots.groupplots}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\begin{document}
\begin{tikzpicture}

\begin{groupplot}[group style={group size=2 by 1}, scale only axis,
axis on top=true]

% Plot main figure (a)
\nextgroupplot[scale only axis,clip marker paths=true,
xmin=0,
xmax=100,
ymin=0,
ymax=550]