如何使用 `\draw` 命令添加标签?

如何使用 `\draw` 命令添加标签?

我有以下情节。 在此处输入图片描述

我如何给该图中的点添加标签?

我已经尝试过了\draw[fill, label=A] (-3, 3) circle [radius=1mm];,但是没有用。\node如果我在节点内放置标签,它似乎对我的网格来说太大了。

任何帮助,将不胜感激。

答案1

作为@Andy Wang 答案(+1)的补充,展示如何通过定义点的样式来缩短代码:

\documentclass[border=3.141592]{standalone}
\usepackage{pgfplots} % it load tikz too
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{tikzpicture}[
         > = {Straight Barb[scale=0.8]},
dot/.style = {circle, draw, fill=#1, inner sep=2pt}
                        ] 
\draw[help lines] (-5, -5) grid (5, 5);
% draw coordinate axes
\draw[<->, thick] (-5.5,0) -- (5.5,0) node[right] {$x$};
\draw[<->, thick] (0,-5.5) -- (0,5.5) node[above] {$y$};
% dots
\node[dot=black,  label=A]  at (-3,3) {};
\node[dot=blue,   label=B]  at (-1,1) {};
\node[dot=red,    label=C]  at (2, 3) {};
\node[dot=yellow, label=D]  at (4, 1) {};
\node[dot=green,  label=E]  at (2,-3) {};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
    \begin{tikzpicture}
      \draw[help lines] (-5, -5) grid (5, 5);
      % draw coordinate axes
      \draw[<->, thick](-5.5,0)--(5.5,0)node[right]{$x$};
      \draw[<->, thick](0,-5.5)--(0,5.5)node[above]{$y$};
      \node[circle, draw, fill=black, inner sep=2pt, label=A]  at (-3, 3) {};
      \node[circle, draw, fill=blue, inner sep=2pt, label=B]  at (-1, 1) {};
      \node[circle, draw, fill=red, inner sep=2pt, label=C]  at (2, 3) {};
      \node[circle, draw, fill=yellow, inner sep=2pt, label=D]  at (4, 1) {};
      \node[circle, draw, fill=green, inner sep=2pt, label=E]  at (2, -3) {};
    \end{tikzpicture}
\end{document}

相关内容