如何在 LaTeX 中使用 TikZ 或 pgfplots 绘制图形

如何在 LaTeX 中使用 TikZ 或 pgfplots 绘制图形

在 Latex 中绘制这样的图形的最简单方法是什么? enter image description here 我试过:

\documentclass{report}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
\draw[->,ultra thick] (-8,0)--(8,0) node[right]{$x$};
\draw[->,ultra thick] (0,-8)--(0,8) node[above]{$y$};

  % First, define nodes
  \draw (0,0) node[circle, inner sep=2pt, fill=black, label={below:{$A(0,0)$}}] (A) {};  
  \draw (5,0) node[circle, inner sep=2pt, fill=black, label={below:{$B(5,0)$}}] (B) {};  
  \draw (2,2) node[circle, inner sep=2pt, fill=black, label={below:{$C(2,2)$}}] (C) {}; 
  \draw (1.5,-2) node[circle, inner sep=2pt, fill=black, label={below:{$D(1.5,-2)$}}] (D) {}; 

  % Draw curved path
  \draw[black]  (A) -- (B);
  \draw[black]  (A) -- (C);
  \draw[black]  (A) -- (D);
  \draw[black]  (C) -- (B);
  \draw[black]  (D) -- (B);
  \draw[red]  (A) .. controls +(-0.1,1.5) and +(0.5,2).. (C);
  \path[->] (A)  edge [bend left] node {aaaa} (C);

\end{tikzpicture}

\end{document}

但我不知道如何为此编写代码。

答案1

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\node[circle, inner sep=2pt, fill, label={[inner sep=2pt]left:{$A$}}] (A) at (0,0) {};  
\node[circle, inner sep=2pt, fill, label={[inner sep=2pt]above right:{$B$}}] (B) at (5,0) {};  
\node[circle, inner sep=2pt, fill, label={[inner sep=2pt]above right:{$C$}}] (C) at (2,2) {}; 
\node[circle, inner sep=2pt, fill, label={[inner sep=2pt]below right:{$D$}}] (D) at (1,-1.5) {}; 
\draw (A) -- (B);
\draw (A) -- (C);
\draw (A) -- (D);
\draw (B) -- (C);
\draw (B) -- (D);
\draw (A) to[out=120,  in=170, looseness=2.0] (C);
\draw (A) to[out=100,  in=185, looseness=1.5] (C);
\draw (A) to[out=-10,  in=50,  looseness=2.0] (D);
\draw (A) to[out=-20,  in=80,  looseness=1.5] (D);
\draw (A) to[out=-100, in=160, looseness=1.5] (D);
\draw (A) to[out=-140, in=170, looseness=2.0] (D);
\draw (B) to[out=175,  in=-60, looseness=1.0] (C);
\end{tikzpicture}
\end{document}

Connected graph with four nodes

相关内容