如何用 TikZ 绘制关系的可视化表示

如何用 TikZ 绘制关系的可视化表示

我包含的图形太模糊了,所以我决定找出如何在 TikZ 中绘制以下四个图形。我从未真正使用过 TikZ,所以有人可以解释如何绘制这样的图形吗?

关系可视化

答案1

有一种可能性是:

\documentclass{article}
\usepackage{amssymb}
\usepackage{tikz}

\def\mysquare#1{%
  \node[draw,minimum width=3cm,minimum height=3cm] (#1) {};
  \draw[->] (#1.east) -- +(10pt,0) node[label=below :$\mathbb{R}$] {};
  \draw (#1.west) -- +(-10pt,0);
  \draw[->] (#1.north) -- +(0,10pt) node[label=right :$\mathbb{R}$] {};
  \draw (#1.south) -- +(0,-10pt);
}

\begin{document}
\begin{tikzpicture}[>=latex]
\mysquare{a}
\draw (a.north west)  -- node[auto,swap,midway] {$R_1$} +(1.5cm,-1.5cm) -- (a.north east);
\begin{scope}[xshift=5cm]
\mysquare{b}
\draw (b.north east)  -- node[auto,swap,midway] {$R_1^{-1}$} +(-1.5cm,-1.5cm) -- (b.south east);
\end{scope}
\begin{scope}[yshift=-5cm]
\mysquare{c}
\filldraw[draw=black,fill=blue!20] (c.north east)  -- (c.north west) -- (c.south west) -- cycle;
\node at ([xshift=15pt,yshift=-15pt]c.north west) {$R_2$};
\end{scope}
\begin{scope}[xshift=5cm,yshift=-5cm]
\mysquare{d}
\filldraw[draw=black,fill=blue!20] (d.north east)  -- (d.south west) -- (d.south east) -- cycle;
\node at ([xshift=-15pt,yshift=15pt]d.south east) {$R_2^{-1}$};
\end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容