2

I am having difficulty drawing the following pictures, so far I have only been able to draw the venn diagrams and not the elements inside them.

enter image description here

enter image description here

My code looks something like

\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}

edit: I have used the comment below to add points but I don't know how to connect them

4
  • 2
    You can use something like \fill (2,3) circle[radius=0.1] node[above left]{a}; Commented Nov 4, 2021 at 15:33
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Commented Nov 4, 2021 at 15:33
  • What does "function" in the title refer to? Have you looked at all the other Venn diagrams on this site? Commented Nov 4, 2021 at 15:35
  • 1
    @hpekristiansen its like relations from one set to another
    – Leafy
    Commented Nov 4, 2021 at 16:08

2 Answers 2

3

I do not like making the ellipse/circles nodes, so here is an alternative way where they are simply drawn:

\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}

Functional Venn diagram

1

You can have this figure: enter image description here

with this code:

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .