I have the following three-dimensional surface plot and I would like to add a gradient to the red semitransparent area starting with black at x=0
and ending with white at x=1
. Is it possible to add a gradient to the fill between
command?
Alternatively, it might be possible to draw the area with the patchplots
library. However, I wasn't able to reproduce the area with the patchplots
library and the patch type=polygon
command, so I wasn't able to check if it is possible to add a gradient this way.
MWE:
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
enlargelimits=false,
axis lines=center,
height=10cm,
xmin=0, xmax=1.0,
ymin=0, ymax=1.0,
zmin=0, zmax=1.0,
xtick=\empty, ytick=\empty, ztick=\empty,
xlabel=$x$, ylabel=$y$, zlabel=$z$,
axis equal,
view={130}{25},
enlargelimits=upper,
clip=false,
axis on top,
set layers,
]
\begin{pgfonlayer}{axis background}
\addplot3[
ultra thin,
trig format plots=rad,
surf,
faceted color=black!50,
point meta={sqrt(x^2 +y^2)},
colormap={white}{color=(white) color=(black!15)},
domain=0.001:pi/2,
unbounded coords=jump,
samples=81,
y domain=pi/2:2*pi,
samples y = 51,
z buffer=sort,
] ({sin(x)*cos(y)},{sin(x)*sin(y)},{(sin(10*x) / (10*x))});
\end{pgfonlayer}
\begin{pgfonlayer}{axis foreground}
\addplot3[
very thick,
trig format plots=rad,
draw=red,
domain=0.001:pi/2,
samples=81,
y domain=pi/2:2*pi,
samples y = 1,
name path=A,
] ({sin(x)*cos(y)},{sin(x)*sin(y)},{(sin(10*x) / (10*x))});
\addplot3 [name path=B, draw=none,samples=2, domain=0:1] ({x},0,0);
\addplot[red,opacity=0.4] fill between [of=A and B];
\end{pgfonlayer}
\end{axis}
\end{tikzpicture}
\end{document}