在 tikzpicture 中,在轴环境中,我正在上传一个图形
\addplot graphics[xmin=0,ymin=-.15,xmax=10,ymax=1.1] {figure.png};
在这个图上我可以画两条线
\addplot [name path=line1,color=red] table[row sep=crcr]{...data1...};
\addplot [name path=line3,color=red] table[row sep=crcr]{...data2...};
line1
现在我通常会在和line2
之间添加均匀的填充
\addplot[blue] fill between[of=line1 and line2];
但是这不起作用,因为它与之前添加的图形重叠。有没有办法让填充与图形重叠?我还能怎么做?
MWE 将是
\documentclass{article}
\usepackage{pgfplots}
\usepackage{amsmath}
\begin{document}
\begin{figure}
\usepgfplotslibrary{fillbetween}
\begin{tikzpicture}
\begin{axis}[xmin=0,ymin=0,xmax=4,ymax=16]
\addplot [name path=line1,color=red, line width=1.5pt]
table[row sep=crcr]{%
0 0\\
1 1\\
2 4\\
3 9\\
4 16\\
};
\addplot graphics[xmin=0,ymin=0,xmax=4,ymax=16] {figure.png};
\addplot [name path=line2,color=blue, line width=1.5pt]
table[row sep=crcr]{%
0 0\\
1 1\\
2 2\\
3 3\\
4 4\\
};
\addplot[olive] fill between[of=line1 and line2];
\end{axis}
\end{tikzpicture}%
\end{figure}
\end{document}
答案1
on layer=axis background
只需添加的选项即可addplot
。以下代码将起作用
\documentclass{article}
\usepackage{pgfplots}
\usepackage{amsmath}
\begin{document}
\begin{figure}
\usepgfplotslibrary{fillbetween}
\begin{tikzpicture}
\begin{axis}[xmin=0,ymin=0,xmax=4,ymax=16]
\addplot [name path=line1,color=red, line width=1.5pt]
table[row sep=crcr]{%
0 0\\
1 1\\
2 4\\
3 9\\
4 16\\
};
\addplot[on layer=axis background] graphics[xmin=0,ymin=0,xmax=4,ymax=16] {figure.png};
\addplot [name path=line2,color=blue, line width=1.5pt]
table[row sep=crcr]{%
0 0\\
1 1\\
2 2\\
3 3\\
4 4\\
};
\addplot[olive] fill between[of=line1 and line2];
\end{axis}
\end{tikzpicture}%
\end{figure}
\end{document}