# Is it possible to make a gradient from 'opaque color' to 'total transparency'?

It seems like the 'color' transparent acts just like black (changing opacity acts as some kind of gray):

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\begin{document}
\begin{tikzpicture}
\begin{axis}[]

\addplot[blue, name path=A,mark=none] coordinates {(-10,3) (7.5,3)};
\addplot[transparent, name path=B,mark=none] coordinates {(-10,3) (7.5,0.9)};
\addplot[top color=blue, bottom color=white] fill between[of=A and B];

\addplot[red, name path=C, mark=none] coordinates {(-11,2.7) (7,2.7)};
\addplot[transparent, name path=D,mark=none] coordinates {(-11,2.3) (7,2.3)};
\addplot[top color=red, bottom color=white] fill between[of=C and D];

\addplot[red, name path=E, mark=none] coordinates {(-11,2.1) (7,2.1)};
\addplot[transparent, name path=F,mark=none] coordinates {(-11,1.7) (7,1.7)};
\addplot[top color=red, bottom color=transparent] fill between[of=E and F];

\addplot[red, name path=G, mark=none] coordinates {(-11,1.5) (7,1.5)};
\addplot[transparent, name path=H,mark=none] coordinates {(-11,1.1) (7,1.1)};
\addplot[opacity=0.5, top color=red, bottom color=white] fill between[of=G and H];

\end{axis}
\end{tikzpicture}
\end{document}


Another problem are the contour lines around the polygons (except the top ones, which are intended to appear).

To ease playing around: online edit/preview

• I am not so sure. Even with olive, the end of the gradient becomes gray. With opacity=1, the last lines are white; with opacity=0.9 they become darker. The darkest point seems to be at opacity=0.5. From there until opacity=0, it goes in the opposite direction. So, the peak of 'grayness' seems to be at opacity=0.5. Which is counterintuitive, when talking about transparency with a white background.
– olyk
Sep 2 '15 at 15:18

Do you want something like this?

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[]

\addplot[blue, name path=A,mark=none] coordinates {(-10,2) (8,2)};
\addplot[transparent, name path=B,mark=none] coordinates {(-10,2) (8,0.4)};
\addplot[top color=blue, bottom color=white] fill between[of=A and B];

\addplot[red, name path=C, mark=none] coordinates {(-11,1.7) (7,1.7)};
\addplot[transparent, name path=D,mark=none] coordinates {(-11,1.3) (7,1.3)};
\addplot[top color=red, bottom color=white] fill between[of=C and D];

\addplot[red, name path=E, mark=none] coordinates {(-11,1.1) (7,1.1)};
\addplot[transparent, name path=F,mark=none] coordinates {(-11,0.7) (7,0.7)};
\end{axis}
\end{tikzpicture}
\end{document}

• Yep, precisely that!
– olyk
Sep 2 '15 at 16:06
• Is it possible to change the pace of the gradient, like a logarithmic one instead of a linear one?
– olyk
Sep 2 '15 at 16:08
• Maybe, I might have found it: tex.stackexchange.com/questions/237867/…
– olyk
Sep 2 '15 at 16:10
• @davips I don't think there is anything built in. I have no idea whether you could create an extension to the fadings library which would do that. If you can create it as a black-and-white picture, you can base the fading on the picture, though.
– cfr
Sep 2 '15 at 16:11
• @davips That does, indeed, look close to what you need. So, yes, I take it you can. You need to do the set up in the preamble for a fading (as opposed to a shading), though.
– cfr
Sep 2 '15 at 16:15