我需要按字母順序替換圖中的索引號。例如,在下圖中,我想看到 a,b,c,...,而不是 0,1,2,...
\documentclass{standalone}
% This file is an extract of the PGFPLOTS manual, copyright by Christian Feuersaenger.
% http://pgfplots.sourceforge.net/pgfplots.pdf
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view/h=120,xlabel=$x$,ylabel=$y$]
% replicate the vertex list to show \coordindex:
\addplot[only marks,nodes near coords={\coordindex}]
coordinates {(1,1) (2,2) (3,1)};
\addplot [red,mark=square] coordinates {(1,1) (2,2) (3,1)};
\end{axis}
\end{tikzpicture}
\end{document}
我的想法是用“a”97的ascii代碼\coordindex
之和替換\coordindex
。
答案1
也許有一個更簡單的方法,但你可以使用計數器:
如果您需要大寫標籤,可以使用\Alph{}
代替\alph{}
。
代碼:
\documentclass{standalone}
% This file is an extract of the PGFPLOTS manual, copyright by Christian Feuersaenger.
% http://pgfplots.sourceforge.net/pgfplots.pdf
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\usepgfplotslibrary{patchplots}
\newcounter{LabelCounter}
\newcommand{\Letter}[1]{\setcounter{LabelCounter}{\numexpr#1+1\relax}\alph{LabelCounter}}%
\begin{document}
\begin{tikzpicture}
\begin{axis}[view/h=120,xlabel=$x$,ylabel=$y$]
% replicate the vertex list to show \coordindex:
\addplot[only marks,nodes near coords={\Letter{\coordindex}}]
coordinates {(1,1) (2,2) (3,1)};
\addplot [red,mark=square] coordinates {(1,1) (2,2) (3,1)};
\end{axis}
\end{tikzpicture}
\end{document}