![使用 pgfplots 表格中的文本标签和颜色的散点图](https://linux22.com/image/371962/%E4%BD%BF%E7%94%A8%20pgfplots%20%E8%A1%A8%E6%A0%BC%E4%B8%AD%E7%9A%84%E6%96%87%E6%9C%AC%E6%A0%87%E7%AD%BE%E5%92%8C%E9%A2%9C%E8%89%B2%E7%9A%84%E6%95%A3%E7%82%B9%E5%9B%BE.png)
我想用颜色和文本标签来分散表格中的绘图点。选择颜色适用于类别,但标签被解析为数字并显示为“nan”。
\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[enlargelimits=0.2]
\addplot[
scatter/classes={a={blue}, b={red}},
scatter, mark=*, only marks,
scatter src=explicit symbolic,
nodes near coords*={\label},
visualization depends on=\thisrow{label} \as \label
] table [meta=class] {
x y class label
0.5 0.2 a A
0.2 0.1 b B
0.7 0.6 a C
0.35 0.4 a D
0.65 0.1 a E
};
\end{axis}
\end{tikzpicture}
\end{document}
我如何阻止 pgfplots 解析标签?
答案1
只需添加“价值”即可。
\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[enlargelimits=0.2]
\addplot[
scatter/classes={a={blue}, b={red}},
scatter, mark=*, only marks,
scatter src=explicit symbolic,
nodes near coords*={\Label},
visualization depends on={value \thisrow{label} \as \Label} %<- added value
] table [meta=class] {
x y class label
0.5 0.2 a A
0.2 0.1 b B
0.7 0.6 a C
0.35 0.4 a D
0.65 0.1 a E
};
\end{axis}
\end{tikzpicture}
\end{document}