5

I have the following MWE which draws two fading filled circles:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\fill[inner color=red,outer color=white] (0,0) circle (1.8);
\begin{scope}[xshift=4cm]
\fill[inner color=red,outer color=white] (0,0) circle (1.8);
\end{scope}
\end{tikzpicture}
\end{document}

I would like to change the scope xshift to 3cm. The problem is that the circles overlap with the right circle placed on top of that on the left circle. I want the colour intensity to instead add constructively.

A seperate question: How can I add a Gaussian function on top of the circles without the axes? The examples I saw on the TikZ site used the pgfplots package which draws the axes.

2 Answers 2

5

We use the fadings library (search the \tikzfading documentation in the PGF/TikZ manual.)

The output

enter image description here I think it did not look very pretty with both red disks, so I changed one to blue.

The code

\documentclass[tikz]{standalone}
\usetikzlibrary{fadings}
\tikzfading %strangely gives bad bounding box when inside the tikzpicture
[
  name=fade out,
  inner color=transparent!0,
  outer color=transparent!100
]
\begin{document}
\begin{tikzpicture}
  \tikzset
  {
    myCircle/.style=
    {
      red,
      path fading=fade out,
    }
  }
  \def\a{1}
  \fill[myCircle] (-\a,0) circle (1.8);
  \fill[myCircle, blue,] (\a,0) circle (1.8);
  \draw plot [samples=200] (\x, {exp(-.5*(\x)^2)}) ;
\end{tikzpicture}
\end{document}
3
  • 2
    Marsupilam, thanks! The bounding box can be sorted by moving the \tikzfading and \tikzset commands outside of the \tikzpicture enviroment.
    – Sid
    Feb 1, 2017 at 15:07
  • 2
    Thank you. It is enough to take the tikzfading out. I'll edit.
    – marsupilam
    Feb 1, 2017 at 15:09
  • I had a problem where my standalone figures in a beamer presentation were moving in unexpected ways when using fadings. Putting \tikzfading outside of the \tikzpicture solved it. Do you know whether this is documented somewhere (I could not immediately find it in the tikz manual)?
    – JorenV
    Oct 6, 2020 at 17:58
2

I am a little uncertain of how it works, but I think you need Fadings from the TikZ manual section 23.4. Something like this:

\documentclass[border=0.2 cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\tikzfading[name=fade inside,
inner color=transparent!0,
outer color=transparent!30] 
\begin{tikzpicture}
\shade[ball color=red,path fading=fade inside] (0,0) circle (1.8);
\begin{scope}[xshift=3cm]
\shade[ball color=red,path fading=fade inside] (0,0) circle (1.8);
\end{scope}
\end{tikzpicture}
\end{document}

Balls with fadings

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .