퍼지 논리에 대한 벤 다이어그램

퍼지 논리에 대한 벤 다이어그램

벤 다이어그램을 생성하기 위한 코드 샘플을 많이 보았습니다. 퍼지 논리와 관련하여 유사하지만 다른 다이어그램을 그릴 수 있는 방법을 찾고 있습니다(아래 스크린샷의 두 번째 행 참조). 어떻게 생산할 수 있습니까?

여기에 이미지 설명을 입력하세요

답변1

다음을 사용하여 한 가지 가능성TikZ첫 번째 행과pgfplotsfillbetween두 번째 행에는 해당 라이브러리(패키지의 업데이트된 버전 필요) 와 함께 표시 됩니다. 세 번째 열은 연습용으로 남겨두겠습니다.

\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);
\path[fill=gray!40] (-0.3,0) circle [radius=1.3cm];
\draw[fill=gray!40] (1,0) circle [radius=0.8cm];
\draw (-0.3,0) circle [radius=1.3cm];
\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}
\clip (-0.3,0) circle [radius=1.3cm];
\fill[gray!40] (1,0) circle [radius=0.8cm];
\end{scope}
\draw (-0.3,0) circle [radius=1.3cm];
\draw (1,0) circle [radius=0.8cm];
\node at (-0.3,0) {$A$};
\node at (1.3,0) {$B$};
\end{tikzpicture}%
}\par
\subcaptionbox{}{%
\begin{tikzpicture}
\begin{axis}[
]
\addplot[name path=A] {gauss(0,0.5)};
\addplot[name path=B] {gauss(1,0.5)};
\path[name path=axis] (axis cs:-2,0) -- (axis cs:3,0);    
\addplot[gray!40] fill between[of=A and axis];
\addplot[gray!40] fill between[of=A and B];
\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}
\addplot[name path=A] {gauss(0,0.5)};
\addplot[name path=B] {gauss(1,0.5)};
\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);    
\addplot[gray!40]
  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}

여기에 이미지 설명을 입력하세요

답변2

Gonzalo Medina의 솔루션을 고려할 때 이 제안은 환경 clip내 기술이 사용되는 보완 솔루션을 제공합니다.scope

참고: pgfplots 패키지의 업데이트된 버전이 없는 경우.

여기에 이미지 설명을 입력하세요

암호

\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);
\addplot[fill=blue!20!white] {gauss(0,0.5)};
\addplot[fill=blue!20!white] {gauss(1,0.5)};
\end{scope} 
\addplot[thick] {gauss(0,0.5)};
\addplot[thick] {gauss(1,0.5)};
\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);
\addplot[fill=blue!20!white] {gauss(1,0.5)};
\end{scope} 
\begin{scope}
\clip[] (axis cs:0.5,0) rectangle (axis cs:4,0.8);
\addplot[fill=blue!20!white] {gauss(0,0.5)};
\end{scope} 
\addplot[thick] {gauss(0,0.5)};
\addplot[thick] {gauss(1,0.5)};
\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);
\path[fill=white] (1,0) circle [radius=0.8cm];
\path[fill=white] (-0.3,0) circle [radius=1.3cm];
\draw[thick] (1,0) circle [radius=0.8cm];
\draw[thick] (-0.3,0) circle [radius=1.3cm];
\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);
\addplot[fill=white] {gauss(0,0.5)};
\addplot[fill=white] {gauss(1,0.5)};
\end{scope} 
\addplot[thick] {gauss(0,0.5)};
\addplot[thick] {gauss(1,0.5)};
\node at (axis cs:0,0.9) {$A$};
\node at (axis cs:1,0.9) {$B$};
\end{axis}
\end{tikzpicture}


\end{document}

관련 정보