如何在 Tikz 中绘制一个非常简单的图表?

如何在 Tikz 中绘制一个非常简单的图表?

我想绘制一个由一个点和一个箭头组成的图表,该箭头从点上方开始,绕一圈并回到点的右侧,如下所示: 在此处输入图片描述

但是,我对 Tikz 不太了解,我制作出来的效果看起来像苍蝇粪便。我该怎么做?

答案1

这些都是精确的弧:

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta,bending}
\begin{document}
\begin{tikzpicture}[>={Stealth[flex]}]
\node[circle,fill=black,inner sep=0pt,
      minimum size=4pt,label=below:0] (0) at (0,0) {};
\node[circle,fill=black,inner sep=0pt,
      minimum size=4pt,label=below:1] (1) at (4,0) {};
\draw[->] ([xshift=.5cm]0.east) -- ([xshift=-.5cm]1.west);
\draw[->] (0.center)++(0,.35)++(-120:.35) arc (240:-60:.35);
\draw[->] (1.center)++(0,.35)++(-120:.35) arc (240:-60:.35);
\end{tikzpicture}
\end{document}

在此处输入图片描述

这些是更好的弧:

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta,bending}
\begin{document}
\begin{tikzpicture}[>={Stealth[flex]}]
\node[circle,fill=black,inner sep=0pt,
      minimum size=4pt,label=below:0] (0) at (0,0) {};
\node[circle,fill=black,inner sep=0pt,
      minimum size=4pt,label=below:1] (1) at (4,0) {};
\draw[->] ([xshift=.5cm]0.east) -- ([xshift=-.5cm]1.west);
\draw[->] (0.center)++(0,.45)++(-120:.35) arc (240:-60:.35);
\draw[->] (1.center)++(0,.45)++(-120:.35) arc (240:-60:.35);
\end{tikzpicture}
\end{document}

在此处输入图片描述

虽然这些不是圆弧,但我建议:

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta,bending}
\begin{document}
\begin{tikzpicture}[>={Stealth[flex]}]
\node[circle,fill=black,inner sep=0pt,
      minimum size=4pt,label=below:0] (0) at (0,0) {};
\node[circle,fill=black,inner sep=0pt,
      minimum size=4pt,label=below:1] (1) at (4,0) {};
\node[circle,minimum size=.8cm] (0x) at (0,0) {};
\node[circle,minimum size=.8cm] (1x) at (4,0) {};
\draw[->] (0x) -- (1x);
\draw (0x) edge[out=120,in=60,loop] ();
\draw (1x) edge[out=120,in=60,loop] ();
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

如果不需要精确的圆圈,可以采用以下简单方法......

代码

\documentclass[border=3pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows.meta}



\begin{document}

\begin{tikzpicture}
\node (A) at (0,0) {};
\node (B) at (3,0) {};
%
\fill (A) circle (1.5pt) node[below] {0};
\fill (B) circle (1.5pt) node[below] {1};
%
\draw[-Stealth,thick] (A) -- (B);
\draw[-stealth,gray] (A) to[out=130,in=50,looseness=10] (A);
\draw[-stealth,gray] (B) to[out=130,in=50,looseness=10] (B);
\end{tikzpicture}

\end{document}

输出

在此处输入图片描述

相关内容