绘制函数维恩图

绘制函数维恩图

我在绘制以下图形时遇到了困难,到目前为止,我只能绘制维恩图,而不能绘制其中的元素。

在此处输入图片描述

在此处输入图片描述

我的代码看起来像

\documentclass[12pt]{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
 
% Circle with label
\node[draw,
    circle,
    minimum size =2cm,
    label={135:$X$}] (circle1) at (-1,0){}; 

\fill (-1.5,0) circle[radius=0.1] node[above left]{a}; 

\node[draw,
    circle,
    minimum size =2cm,
    label={45:$Y$}] (circle2) at (3,0){};
 
\end{tikzpicture}
\end{document}

编辑:我已使用下面的评论添加要点,但我不知道如何将它们联系起来

答案1

我不喜欢制作椭圆/圆形节点,因此这里有一种简单绘制的替代方法:

\documentclass[tikz, border=1 cm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw[thick] (0,0) ellipse[x radius=2, y radius=3] +(-1.5,3) node{A};
\draw[thick] (7,0) ellipse[x radius=2, y radius=3] +(1.5,3) node{B};
\coordinate (a) at (0.5,2);
\coordinate (b) at (-1,1.5);
\coordinate (c) at (1,0);
\coordinate (p) at (6,1.5);
\fill (a) circle[radius=0.1] node[above left]{a};
\fill (b) circle[radius=0.1] node[below right]{b};
\fill (c) circle[radius=0.1] node[below left]{c};
\fill (p) circle[radius=0.1] node[below right]{p};
\draw[-Latex, shorten <=5pt, shorten >=5pt] (a) to[out=20, in=160] (p);
\draw[-Latex, shorten <=5pt, shorten >=5pt] (c) to[out=40, in=200] (p);
\end{tikzpicture}
\end{document}

功能维恩图

答案2

你可以得到这个数字: 在此处输入图片描述

使用以下代码:

\documentclass[12pt]{article}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}[scale=2]
        % set A
        \draw[line width=1pt] (0,0) ellipse (1cm and 2cm);
        \node[above] at (0,2.2) (A) {$A$};
        \fill (0,1.4) circle(1pt) node[left] (a) {$a$}; 
        \fill (-0.5,0.7) circle(1pt) node[left] (b) {$b$};
        \fill (0,0) circle(1pt) node[left] (c) {$c$};
        \fill (-0.5,-0.7) circle(1pt) node[left] (d) {$d$};
        \fill (0,-1.4) circle(1pt) node[left] (e) {$e$};
        
        %set B
        \draw[line width=1pt] (5,0) ellipse (1cm and 2cm);
        \node[above] at (5,2.2) (B) {$B$};
        \fill (5,1.4) circle(1pt) node[right] (p) {$p$}; 
        \fill (4.5,0.6) circle(1pt) node[right] (q) {$q$};
        \fill (5,-0.2) circle(1pt) node[right] (r) {$r$};
        \fill (4.5,-1.0) circle(1pt) node[right] (s) {$s$};
        
        % relations
        \draw[-latex,cyan] (a) -- (p);
        \draw[-latex,cyan] (c) -- (p);
        \draw[-latex,cyan] (c) -- (s);
        \draw[-latex,cyan] (d) -- (s);
        \draw[-latex,cyan] (e) -- (q);
        
        \node[below] at (2.5,-2.2) {A relation $R \subseteq A\times B$ with $R=\{(a,p),(c,p),(c,s),(d,s),(e,q)\}$}; 
    \end{tikzpicture}
\end{document}

相关内容