5

Is it possible to make a 4-set venn diagram using the tikz packages, like the following one? I know it must be, but the only information I can find on the subject uses R as the language.

enter image description here

So, an update. I am now wondering how to best fill just the isolated fields, that is, the part only in A, the part only in B, etc. For now, I have just the part in D filled. Any suggestions? Code below:

\documentclass[12pt]{article}

\usepackage{tikz} \usetikzlibrary{positioning,shapes.geometric}

% For drawing
\def\firstellip{(1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}
\def\secondellip{(0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm,
rotate=50]} \def\thirdellip{(-1.6, 0) ellipse [x radius=3cm, y radius=1.5cm,
rotate=-50]} \def\fourthellip{(-0.3, 1cm) ellipse [x radius=3cm, y
radius=1.5cm, rotate=-50]} \def\bounding{(-5,-3) rectangle (5,4)}

\begin{document}

\begin{tikzpicture} \filldraw[fill=black, opacity=0.2] \bounding;

    \scope \fill[white] \fourthellip; \endscope \filldraw[fill=red,
    opacity=0.2] \fourthellip;

    %single colors
    \scope \fill[white] \secondellip; \fill[white] \thirdellip; \fill[white]
    \firstellip; \endscope

    \draw \firstellip node [label={[xshift=2.0cm, yshift=-0.9cm]$A$}] {};
    \draw \secondellip node [label={[xshift=2.2cm, yshift=2.1cm]$B$}] {};
    \draw \thirdellip node [label={[xshift=-2.0cm, yshift=-0.9cm]$C$}] {};
    \draw \fourthellip node [label={[xshift=-2.2cm, yshift=2.1cm]$D$}] {};
    \draw \bounding node [label=above left:$U$] {};

\end{tikzpicture}  \end{document}

And displays as follows, I'm trying to get red in the four "corners". Thanks so much:

enter image description here

2

There are some Venn diagrams with multiple elements coloured in this example: http://www.texample.net/tikz/examples/venn-diagram/

I've taken the principles used there and created a version with all four "corners" filled, as requested (I used yellow to distinguish from the original code which had one corner coloured red).

Venn with corners coloured

\documentclass[12pt]{article}

\usepackage{tikz} \usetikzlibrary{positioning,shapes.geometric}

% For drawing
\def\firstellip{(1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}
\def\secondellip{(0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm,
rotate=50]} \def\thirdellip{(-1.6, 0) ellipse [x radius=3cm, y radius=1.5cm,
rotate=-50]} \def\fourthellip{(-0.3, 1cm) ellipse [x radius=3cm, y
radius=1.5cm, rotate=-50]} \def\bounding{(-5,-3) rectangle (5,4)}

\begin{document}

\begin{tikzpicture} \filldraw[fill=black, opacity=0.2] \bounding;

    \scope \fill[white] \fourthellip; \endscope \filldraw[fill=red,
    opacity=0.2] \fourthellip;

    %single colors
    \scope \fill[white] \secondellip; \fill[white] \thirdellip; \fill[white]
    \firstellip; \endscope

    \draw \firstellip node [label={[xshift=2.0cm, yshift=-0.9cm]$A$}] {};
    \draw \secondellip node [label={[xshift=2.2cm, yshift=2.1cm]$B$}] {};
    \draw \thirdellip node [label={[xshift=-2.0cm, yshift=-0.9cm]$C$}] {};
    \draw \fourthellip node [label={[xshift=-2.2cm, yshift=2.1cm]$D$}] {};
    \draw \bounding node [label=above left:$U$] {};

    \begin{scope}
        \begin{scope}[even odd rule]% first ellipse corner
            \clip \secondellip (-5,-5) rectangle (5,5);
            \clip \thirdellip (-5,-5) rectangle (5,5);
            \clip \fourthellip (-5,-5) rectangle (5,5);
        \fill[yellow] \firstellip;
        \end{scope}
    \end{scope}

    \begin{scope}
        \begin{scope}[even odd rule]% second ellipse corner
            \clip \firstellip (-5,-5) rectangle (5,5);
            \clip \thirdellip (-5,-5) rectangle (5,5);
            \clip \fourthellip (-5,-5) rectangle (5,5);
        \fill[yellow] \secondellip;
        \end{scope}
    \end{scope}

    \begin{scope}
        \begin{scope}[even odd rule]% third ellipse corner
            \clip \secondellip (-5,-5) rectangle (5,5);
            \clip \firstellip (-5,-5) rectangle (5,5);
            \clip \fourthellip (-5,-5) rectangle (5,5);
        \fill[yellow] \thirdellip;
        \end{scope}
    \end{scope}


\end{tikzpicture}  \end{document}

The trick is to add a large rectangle that encompasses everything and then use the even-odd filling rule - see the texample page for more details.

(Btw - I used http://writeLaTeX.com to test the code - the document can be found here: https://www.writelatex.com/77868dfxncz )

  • PS: I saved this version of the answer in the writeLaTeX document - it can always be restored by going to the "history" menu in the writeLaTeX editor and restoring the "Answer to TeX SX question" version. – John Hammersley Feb 27 '13 at 1:40
6

Result

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.geometric}
\begin{document}
\tikzset{
  set/.style ={ 
    ellipse, 
    minimum width=3.5cm, 
    minimum height=2cm,
    draw,
}}
\begin{tikzpicture}
\foreach \x/\y/\a in {.7/0/60,.3/1/60,-.7/0/-60,-.3/1/-60} 
  \node[set, rotate=\a] at (\x,\y) {};
\end{tikzpicture}
\end{document}
  • 1
    Why transform shape ? I think you don't need this option. – Alain Matthes Feb 26 '13 at 19:42
  • @AlainMatthes You are right, it is not needed. I somewhat remembered that without it the node shape wont be rotated, but I was wrong. – JLDiaz Feb 26 '13 at 19:45

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.