如何在轴背景预操作中绘制的另一个填充区域之上的区域之间绘制填充?
梅威瑟:
\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
修复了这个问题: