在散点图中的数据点上添加标签

在散点图中的数据点上添加标签

这个问题是我上一个问题的后续问题:绘制带类别的 XY 轴 我想知道如何在我的数据点上添加标签。

以下是我目前所掌握的信息: 在此处输入图片描述

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
\begin{axis}
[grid=both,ymin=0,ymax=6,xmax=6,xmin=0,xtick={2,4,6},xticklabels={Low,Middle, High},ytick={2,4,6}, yticklabels={Low,Middle, High},xlabel= Classical counterpart,ylabel=Quantization,
every x tick label/.style={xshift=-11mm,anchor=north},
every y tick label/.style={yshift=-8mm,anchor=east}
]
\addplot [only marks] coordinates
{
(0.5,0.2) [(1)]
(0.2,0.1) [(2)]
(0.7,0.6) [(3)]
(0.35,0.4) [(4)]
(0.65,0.1) [(5)] };
\end{axis}
\end{tikzpicture}

\end{document}

答案1

只需添加选项nodes near coords并使用\addplot+

截屏

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
\begin{axis}
[nodes near coords, grid=both, ymin=0,ymax=6,xmax=6,xmin=0,
xtick={2,4,6},xticklabels={Low,Middle, High},
ytick={2,4,6}, yticklabels={Low,Middle, High},
xlabel= Classical counterpart,ylabel=Quantization,
every x tick label/.style={xshift=-11mm,anchor=north},
every y tick label/.style={yshift=-8mm,anchor=east}
]
\addplot+ [only marks] coordinates
{
(0.5,0.2) [(1)]
(0.2,0.1) [(2)]
(0.7,0.6) [(3)]
(0.35,0.4) [(4)]
(0.65,0.1) [(5)] };
\end{axis}
\end{tikzpicture}

\end{document}

相关内容