答案1
感谢您的代码!(将来,请将其添加到问题中,以便其他人不必添加因在评论中添加代码而丢失的换行符。)
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=7cm, height=9cm, clip=false, xmin=0,xmax=20, ymin=0,ymax=40,
declare function={f(\y)=max(5,min(14,9*\y/20+1/2));
g(\y)=max(10,min(16,6*\y/20+7));},
view={0}{90},colorbar,
/tikz/every pin edge/.style={stealth-,thin}]
\begin{scope}
\clip[variable=\y] plot[samples at={0,10,30,40}] ({f(\y)},\y)
-- plot[samples at={40,30,10,0}] ({g(\y)},\y) -- cycle;
\addplot3[surf,shader=interp,point meta={g(y)-f(y)},domain=5:16,
domain y=0:40] {x};
\end{scope}
\draw[variable=\y] plot[samples at={0,10,30,40}] ({f(\y)},\y)
-- plot[samples at={40,30,10,0}] ({g(\y)},\y) -- cycle;
\addplot3[black,thick,samples at={0,10,30,40},samples y=0] ({f(x)},x,0)
coordinate[pos=0.55,pin=120:{$f(x)$}];
\addplot3[black,thick,samples at={0,10,30,40},samples y=0] ({g(x)},x,0)
coordinate[pos=0.45,pin=-60:{$g(x)$}];
\end{axis}
\end{tikzpicture}
\end{document}
这会“反转”颜色条:
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=7cm, height=9cm, clip=false, xmin=0,xmax=20, ymin=0,ymax=40,
declare function={f(\y)=max(5,min(14,9*\y/20+1/2));
g(\y)=max(10,min(16,6*\y/20+7));},
view={0}{90},colorbar,
/tikz/every pin edge/.style={stealth-,thin},
colorbar style={yticklabel={$\pgfmathparse{-1*\tick}%
\pgfmathprintnumber\pgfmathresult$}}]
\begin{scope}
\clip[variable=\y] plot[samples at={0,10,30,40}] ({f(\y)},\y)
-- plot[samples at={40,30,10,0}] ({g(\y)},\y) -- cycle;
\addplot3[surf,shader=interp,point meta={f(y)-g(y)},domain=5:16,
domain y=0:40] {x};
\end{scope}
\draw[variable=\y] plot[samples at={0,10,30,40}] ({f(\y)},\y)
-- plot[samples at={40,30,10,0}] ({g(\y)},\y) -- cycle;
\addplot3[black,thick,samples at={0,10,30,40},samples y=0] ({f(x)},x,0)
coordinate[pos=0.55,pin=120:{$f(x)$}];
\addplot3[black,thick,samples at={0,10,30,40},samples y=0] ({g(x)},x,0)
coordinate[pos=0.45,pin=-60:{$g(x)$}];
\end{axis}
\end{tikzpicture}
\end{document}