答案1
可能有更简单的方法来实现这一点,但你可以从图中创建一个淡入淡出并将其应用于填充渐变的矩形:
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=1.18}
\usetikzlibrary{fadings, fit}
\begin{document}
\begin{tikzpicture}
\begin{axis}[tick style={transparent!100}]
\addplot[
transparent!0,
line width=2pt
] coordinates {(0,0) (1,1) (2,0.5) (3,1.5) (4,0)};
\end{axis}
\begin{tikzfadingfrompicture}[name=plot fading]
\begin{scope}[local bounding box=plot bbox]
\begin{axis}[tick style={transparent!100}]
\addplot[
transparent!0,
line width=2pt
] coordinates {(0,0) (1,1) (2,0.5) (3,1.5) (4,0)};
\end{axis}
\end{scope}
\end{tikzfadingfrompicture}
\fill[top color=blue, bottom color=cyan, path fading=plot fading, fit fading=false, fading transform={shift={(plot bbox.center)}}]
(plot bbox.north west) rectangle (plot bbox.south east);
\end{tikzpicture}
\end{document}