在轴背景顶部之间填充

在轴背景顶部之间填充

如何在轴背景预操作中绘制的另一个填充区域之上的区域之间绘制填充?

梅威瑟:

\documentclass{article}

\usepackage{pgfplots, pgfplotstable}
\usepgfplotslibrary{groupplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{calc}
\usetikzlibrary{shapes,arrows}
\pgfplotsset{grid style={dashed}}

\begin{document}

\begin{tikzpicture}
    \begin{groupplot}[group style={group size=1 by 2}]
        \nextgroupplot[
            grid,
            axis background/.style={%
                preaction={
                    path picture={
                        \fill [black!5] (axis cs:2,0) rectangle (rel axis cs:1,1);
                    }
                }
            }
        ]
        \addplot[name path=path1] table {
            0 0
            1 1
            2 2
            3 3
            4 5
        };
        \addplot[name path=path2] table {
            0 1
            1 2
            2 3
            3 4
            4 6
        };
        \addplot[fill=red, forget plot, fill opacity=0.25] fill between[of=path1 and path2];

        \nextgroupplot[
            grid,
            axis background/.style={%
                preaction={
                    path picture={
                        \fill [black!5] (axis cs:8,0) rectangle (rel axis cs:1,1);
                    }
                }
            }
        ]
   \end{groupplot}
\end{tikzpicture}

\end{document}

截屏

答案1

我刚刚发现添加set layers, cell picture=true修复了这个问题:

在此处输入图片描述

相关内容