# Venn diagrams for fuzzy logic

I've seen a lot of code samples for producing Venn diagrams. I'm looking for a way to draw similar but different diagrams related to fuzzy logic (see the second row in the screenshot below). How could I produce those? • @Jubobs - thanks for changing "vein diagrams" to "Venn diagrams". – Mico Mar 19 '14 at 20:28
• Could you show what you've tried so far? Starting from scratch ain't much fun. Could you link to existing questions that may be relevant? – cmhughes Mar 19 '14 at 20:39
• Vassili, I suggest tikz. Each curve you want looks like half a sine curve, or a Gaussian bell. These are not hard to draw. – nickie Mar 19 '14 at 21:56

One possibility using TikZ for the first row and pgfplots together with its fillbetween library (requires an updated version of the package) for the second row. The third column is left as an exercise:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{subcaption}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}

\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\pgfplotsset{
xticklabels=\empty,
yticklabels=\empty,
xtick=\empty,
ytick=\empty,
width=6cm,
height=6cm,
every axis plot post/.append style={
mark=none,
domain=-2:3,
samples=50,
smooth
},
ymax=1,
enlargelimits=upper,
}

\begin{document}

\begin{figure}
\subcaptionbox{}{%
\begin{tikzpicture}
\draw (-2.2,-2.2) rectangle (2.2,2.2);
\node at (-0.3,0) {$A$};
\node at (1.3,0) {$B$};
\end{tikzpicture}%
}
\subcaptionbox{}{%
\begin{tikzpicture}
\draw (-2.2,-2.2) rectangle (2.2,2.2);
\begin{scope}
\end{scope}
\node at (-0.3,0) {$A$};
\node at (1.3,0) {$B$};
\end{tikzpicture}%
}\par
\subcaptionbox{}{%
\begin{tikzpicture}
\begin{axis}[
]
\path[name path=axis] (axis cs:-2,0) -- (axis cs:3,0);
\node at (axis cs:0,0.9) {$A$};
\node at (axis cs:1,0.9) {$B$};
\end{axis}
\end{tikzpicture}%
}
\subcaptionbox{}{%
\begin{tikzpicture}
\begin{axis}
\path[name path=lower,
intersection segments={of=A and B,sequence=B0 -- A1}];
\path[name path=axis] (axis cs:-2,0) -- (axis cs:3,0);
fill between[of=axis and lower];
\node at (axis cs:0,0.9) {$A$};
\node at (axis cs:1,0.9) {$B$};
\end{axis}
\end{tikzpicture}%
}
\end{figure}

\end{document} If I may, given Gonzalo Medina's solution, this proposal provides a complement solution where clip technique within scope environment is used.

Note: For those without updated version of the pgfplots package. Code

\documentclass[border=10pt]{standalone}%{article}
\usepackage{pgfplots}

\pgfplotsset{compat=1.8}

\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\pgfplotsset{
xticklabels=\empty,
yticklabels=\empty,
xtick=\empty,
ytick=\empty,
width=6cm,
height=6cm,
every axis plot post/.append style={
mark=none,
domain=-2:3,
samples=50,
smooth
},
ymax=1,
enlargelimits=upper,
}

\begin{document}

%\begin{figure}
\begin{tikzpicture}        % 1st diagram
\begin{axis}
\begin{scope}
\clip[] (axis cs:-2,0) rectangle (axis cs:4,0.8);
\end{scope}
\node at (axis cs:0,0.9) {$A$};
\node at (axis cs:1,0.9) {$B$};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}       % 2nd diagram
\begin{axis}
\begin{scope}
\clip[] (axis cs:-2,0) rectangle (axis cs:0.5,0.8);
\end{scope}
\begin{scope}
\clip[] (axis cs:0.5,0) rectangle (axis cs:4,0.8);
\end{scope}
\node at (axis cs:0,0.9) {$A$};
\node at (axis cs:1,0.9) {$B$};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}       % 3rd diagram
\begin{scope}
\draw[fill=blue!20!white] (-2.2,-2.2) rectangle (2.2,2.2);
\end{scope}
\node at (-0.3,0) {$A$};
\node at (1.3,0) {$B$};
\end{tikzpicture}
\begin{tikzpicture}       % 4th diagram
\begin{axis}
\begin{scope}
\draw[fill=blue!20!white] (axis cs:-2,0) rectangle (axis cs:4,0.8);
\clip (axis cs:-2,0) rectangle (axis cs:4,0.8);
\node at (axis cs:0,0.9) {$A$};
\node at (axis cs:1,0.9) {$B$};