1

Using the solution present in Groupplot to generate group plots and Fill Between-under curve to shade area under the curve generated by a scatter plot, I am having issues with the output. It is always filling the chart area with white. Here is a sample code

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.10}
\usetikzlibrary{pgfplots.groupplots}
%\pgfplotsset{plot coordinates/math parser=false}

\makeatletter
\pgfplotsset{
    groupplot xlabel/.initial={},
    every groupplot x label/.style={
        at={($({group c1r\pgfplots@[email protected]}|-{group c1r\pgfplots@[email protected] south})!0.5!({group c\pgfplots@group@columns r\pgfplots@[email protected]}|-{group c\pgfplots@group@columns r\pgfplots@[email protected] south})$)},
        anchor=north,
    },
    groupplot ylabel/.initial={},
    every groupplot y label/.style={
            rotate=0,
        at={($({group c1r1.north}-|{group c1r1.outer
west})!0.5!({group c1r\pgfplots@[email protected]}-|{group c1r\pgfplots@[email protected] west})$)},
        anchor=east
    },
    execute at end groupplot/.code={%
      \node [/pgfplots/every groupplot x label]
{\pgfkeysvalueof{/pgfplots/groupplot xlabel}};  
      \node [/pgfplots/every groupplot y label] 
{\pgfkeysvalueof{/pgfplots/groupplot ylabel}};  
    },
    group/only outer labels/.style =
{
group/every plot/.code = {%
    \ifnum\pgfplots@group@current@row=\pgfplots@group@rows\else%
        \pgfkeys{xticklabels = {}, xlabel = {}}\fi%
    \ifnum\pgfplots@group@current@column=1\else%
        \pgfkeys{yticklabels = {}, ylabel = {}}\fi%
}
}
}

\def\endpgfplots@environment@groupplot{%
    \endpgfplots@environment@opt%
    \pgfkeys{/pgfplots/execute at end groupplot}%
    \endgroup%
}
\makeatother
\begin{filecontents}{data.dat}
    sat1    etc1    sat2    etc2    sat3    etc3    sat4    etc4
    0   0.06    0   0.10    0   0.17    0   0.25
    10  0.09    10  0.15    10  0.23    10  0.31
    20  0.13    20  0.22    20  0.30    20  0.37
    30  0.15    30  0.27    30  0.36    30  0.43
    40  0.17    40  0.31    40  0.42    40  0.49
    50  0.19    50  0.31    50  0.46    50  0.53
    60  0.20    60  0.32    60  0.47    60  0.54
    70  0.22    70  0.33    70  0.48    70  0.55
    80  0.24    80  0.34    80  0.49    80  0.56
    90  0.25    90  0.35    90  0.50    90  0.57
    100 0.27    100 0.35    100 0.51    100 0.58
\end{filecontents}

\begin{document}
\pgfplotstableread{data.dat}{\1}

\begin{tikzpicture}
\pgfplotsset{%
    label style={font=\scriptsize},
    tick label style={font=\scriptsize},
    axis line style={<->},
      width=4cm,
      height=4cm,
      scale only axis
    }
\begin{groupplot}[%
          group style={group size=2 by 1,
          horizontal sep=5pt,
          vertical sep=5pt},
        xtick={0,10,20,30,40,50,60,70,80,90},
        xticklabels={0,10,20,30,40,50,60,70,80,90},
        yticklabels={0,0.1,0.2,0.3,0.4,0.5,0.6},
        ytick={0,0.1,0.2,0.3,0.4,0.5,0.6},
        groupplot ylabel={Y label},
        groupplot xlabel={X label},
        group/only outer labels
%       legend style={legend cell align=right,legend plot pos=right}
]

% ROW 1
\nextgroupplot[
  xmin=0,
  xmax=100,
  ymin=0,
  ymax=0.6,
 title=\textbf{$\phi=25\%$},every axis title/.style={below right,at={(0,1)},draw=black,fill=white}
]
\addplot+ [smooth,blue,name path=A] table[x={sat4}, y={etc4}] {\1};
\addplot+[draw=none,name path=B, domain=1:50, mark=none] {1}; 
\addplot+[gray, fill opacity=0.4] fill between[of=A and B,soft clip={domain=1:50}];
\nextgroupplot[
%  ylabel={E=10 GPa},
  xmin=0,
  xmax=100,
  ymin=0,
  ymax=0.6,
  title=\textbf{$\phi=30\%$},every axis title/.style={below right,at={(0,1)},draw=black,fill=white}
]
\addplot+ [smooth,blue,name path=A] table[x={sat3}, y={etc3}] {\1};
\addplot+[draw=none,name path=B, domain=1:50, mark=none] {1}; 
\addplot+[gray, fill opacity=0.4] fill between[of=A and B,soft clip={domain=1:50}];
\makeatletter
\end{groupplot}
\end{tikzpicture}
\end{document}

I think there seems to be a layering issue which I can't figure out. Alternate suggestions which don't use Fill Between are also welcome.

1
  • You have these warnings: "Package pgf Warning: fill between skipped: the second input path is empty. on i nput line", so it doesn't fill at all (not white but nothing)
    – koleygr
    Commented Jan 22, 2018 at 9:28

1 Answer 1

1

I think this is not the solution you are hoping for, but at least you get a working result. For more details please have a look at the comments in the code.

% used PGFPlots v1.15
    \begin{filecontents}{data.dat}
        sat1    etc1    sat2    etc2    sat3    etc3    sat4    etc4
        0   0.06    0   0.10    0   0.17    0   0.25
        10  0.09    10  0.15    10  0.23    10  0.31
        20  0.13    20  0.22    20  0.30    20  0.37
        30  0.15    30  0.27    30  0.36    30  0.43
        40  0.17    40  0.31    40  0.42    40  0.49
        50  0.19    50  0.31    50  0.46    50  0.53
        60  0.20    60  0.32    60  0.47    60  0.54
        70  0.22    70  0.33    70  0.48    70  0.55
        80  0.24    80  0.34    80  0.49    80  0.56
        90  0.25    90  0.35    90  0.50    90  0.57
        100 0.27    100 0.35    100 0.51    100 0.58
    \end{filecontents}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}
    \usetikzlibrary{
        pgfplots.fillbetween,
        pgfplots.groupplots,
    }
    \pgfplotsset{
        % use this `compat' level or higher so TikZ coordinates don't have to be
        % prefixed by `axis cs:'
        compat=1.11,
%        plot coordinates/math parser=false,
    }
    \makeatletter
        \pgfplotsset{
            groupplot xlabel/.initial={},
            every groupplot x label/.style={
                at={
                    ($ ({group c1r\pgfplots@[email protected]}
                    |-{group c1r\pgfplots@[email protected] south})%
                    !0.5!%
                    ({group c\pgfplots@group@columns r\pgfplots@[email protected]}%
                    |-{group c\pgfplots@group@columns r\pgfplots@[email protected] south}) $)
                },
                anchor=north,
            },
            groupplot ylabel/.initial={},
            every groupplot y label/.style={
                rotate=0,
                at={
                    ($ ({group c1r1.north}-|{group c1r1.outer west})%
                    !0.5!%
                    ({group c1r\pgfplots@[email protected]}%
                    -|{group c1r\pgfplots@[email protected] west}) $)
                },
                anchor=east,
            },
            execute at end groupplot/.code={%
                \node [/pgfplots/every groupplot x label]
                    {\pgfkeysvalueof{/pgfplots/groupplot xlabel}};
                \node [/pgfplots/every groupplot y label]
                    {\pgfkeysvalueof{/pgfplots/groupplot ylabel}};
            },
            group/only outer labels/.style={
                group/every plot/.code = {%
                    \ifnum\pgfplots@group@current@row=\pgfplots@group@rows\else%
                        \pgfkeys{xticklabels = {}, xlabel = {}}\fi%
                    \ifnum\pgfplots@group@current@column=1\else%
                        \pgfkeys{yticklabels = {}, ylabel = {}}\fi%
                },
            },
        }
%        % ---------------------------------------------------------------------
%        % is it intended that these lines cause the axis lines to not be drawn?
%        % This is also one of the causes why the `fill between' stuff isn't drawn.
%        \def\endpgfplots@environment@groupplot{%
%            \endpgfplots@environment@opt%
%            \pgfkeys{/pgfplots/execute at end groupplot}%
%            \endgroup%
%        }
%        % ---------------------------------------------------------------------

    \makeatother
    \pgfplotstableread{data.dat}{\1}
    \pgfplotsset{
        label style={font=\scriptsize},
        tick label style={font=\scriptsize},
        axis line style={<->},
        width=4cm,
        height=4cm,
        scale only axis,
    }
\begin{document}
\begin{tikzpicture}
    \begin{groupplot}[
        group style={
            group size=2 by 1,
            horizontal sep=5pt,
            vertical sep=5pt,
        },
        xtick={0,10,20,30,40,50,60,70,80,90},
        ytick={0,0.1,0.2,0.3,0.4,0.5,0.6},
        % (moved here)
        every axis title/.style={
            below right,
            at={(0,1)},
            draw=black,
            fill=white,
        },
        % ---------------------------------------------------------------------
        groupplot ylabel={Y label},
        groupplot xlabel={X label},
        group/only outer labels,
        %
        % instead of using the above custom keys you can also force the
        % ticklabels to be drawn only on the left and bottom with
        group/xticklabels at=edge bottom,
        group/yticklabels at=edge left,
        % ---------------------------------------------------------------------
    ]

    % ROW 1
    \nextgroupplot[
        xmin=0,
        xmax=100,
        ymin=0,
        ymax=0.6,
        title=\textbf{$\phi=25\%$},
    ]
        \addplot+ [smooth,blue,name path=A] table [x={sat4}, y={etc4}] {\1};
        % you didn't follow the solution given at
        %     <https://tex.stackexchange.com/a/283533>
        % so changing the constant from 1 to 0.6 in the following `\addplot'
        % command would work, but then you have to keep this in sync with the
        % `ymax' value ...
%        \addplot+[draw=none,name path=B, domain=1:50, mark=none] {0.6};
        % ... so I suggest doing this
        \path [name path=B]
            (\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymax}) --
            (\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymax});
        \addplot+ [gray, fill opacity=0.4] fill between [of=A and B,soft clip={domain=1:50}];

    \nextgroupplot[
        xmin=0,
        xmax=100,
        ymin=0,
        ymax=0.6,
        title=\textbf{$\phi=30\%$},
    ]
        \addplot+ [smooth,blue,name path=A] table [x={sat3}, y={etc3}] {\1};
        \path [name path=B]
            (\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymax}) --
            (\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymax});
        \addplot+ [gray, fill opacity=0.4] fill between [of=A and B,soft clip={domain=1:50}];
    \end{groupplot}

    % add axis labels
    \node [
%        red,
        anchor=north,
    ]
        at ($ (group c1r1.below south west)!0.5!(group c2r1.below south east) $)
            {X label};
    \node [
%        red,
        anchor=east,
    ]
        at ($ (group c1r1.left of north west)!0.5!(group c1r1.left of south west) $)
            {Y label};

\end{tikzpicture}
\end{document}

image showing the result of above code

3
  • Thanks...it does help a bit actually. The only thing is that I cannot generate the shaded region in the second graph from your code, can you double check? Commented Jan 22, 2018 at 20:33
  • Actually I was also wondering why the second fill between was working, because currently there is an already reported bug in the PGFPlots Tracker. But I double checked and according to the LOG file I am using v1.15 and not the actual version from SourceForge. Commented Jan 22, 2018 at 21:02
  • Just double checked...it working on my MiKTeX (Windows) but not on TexLive (Linux). Thanks for the link to the bug Commented Jan 23, 2018 at 6:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .