[Tex/LaTex] TikZ: radial shading of a ring

shadingtikz-pgf

I would like to have a radial shading of a ring, from inner color (red) at inner radius r1 > 0 to outer color (white) at outer radius r2 > r1. But with

\filldraw[even odd rule,inner color=red,outer color=white] 
(0,0) circle (2.2)
(0,0) circle (1.8);

the inner circle only masks the shading of the outer circle:

radial shading of a ring

How to choose a finite inner radius for the shading such that the full color starts at r1 = 1.8?

Best Answer

Do you mean something like the first or the second circle?

enter image description here

The code in which they are realized is:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\filldraw[even odd rule,inner color=red,outer color=white] (0,0) circle (2.2);
\draw(0,0) circle (1.8);
\begin{scope}[xshift=6cm]
\filldraw[even odd rule,inner color=red,outer color=red!5] (0,0) circle (1.8);
\draw(0,0) circle (2.2);
\end{scope}
\end{tikzpicture}
\end{document}

As said by percusse, the only possible approach is to define a new radial shading. Here is an example:

\documentclass{article}
\usepackage{tikz}

\pgfdeclareradialshading{ring}{\pgfpoint{0cm}{0cm}}%
{rgb(0cm)=(1,1,1);
rgb(0.7cm)=(1,1,1);
rgb(0.719cm)=(1,1,1);
rgb(0.72cm)=(0.975,0,0);
rgb(0.9cm)=(1,1,1)}

\begin{document}
\begin{tikzpicture}
\filldraw[shading=ring] (0,0) circle (2.2);
\draw[fill=white](0,0) circle (1.8);

\begin{scope}[xshift=6cm]
\filldraw[shading=ring] (0,0) circle (2.2);
\draw(0,0) circle (1.8);
\end{scope}
\end{tikzpicture}
\end{document}

This gives you:

enter image description here

which I guess is your purpose. Notice that the option fill=white is not really needed, but it has been used to compare the two results.

A simple add to customize colors: the option is identical to what defined in How to shade mindmap concepts?.

The code:

\documentclass{article}
\usepackage{tikz}

\makeatletter
\pgfdeclareradialshading[tikz@ball]{ring}{\pgfpoint{0cm}{0cm}}%
{rgb(0cm)=(1,1,1);
rgb(0.719cm)=(1,1,1);
color(0.72cm)=(tikz@ball);
rgb(0.9cm)=(1,1,1)}
\tikzoption{ring color}{\pgfutil@colorlet{tikz@ball}{#1}\def\tikz@shading{ring}\tikz@addmode{\tikz@mode@shadetrue}}
\makeatother

\begin{document}
\begin{tikzpicture}
\filldraw[shading=ring, ring color=red] (0,0) circle (2.2cm);
\draw(0,0) circle (1.8cm);

\begin{scope}[xshift=7cm]
\filldraw[shading=ring] (0,0) circle (3) circle (2.45);
\end{scope}
\end{tikzpicture}
\end{document}

The result:

enter image description here

Related Question