4

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.

4

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}
  • 1
    Marsupilam, thanks! The bounding box can be sorted by moving the \tikzfading and \tikzset commands outside of the \tikzpicture enviroment. – Sid Feb 1 '17 at 15:07
  • 1
    Thank you. It is enough to take the tikzfading out. I'll edit. – marsupilam Feb 1 '17 at 15:09
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.