1

In the following example, how can I use the column label as source for a legend?

\documentclass{article}
\usepackage[a4paper, left =2cm, top = 2cm, right = 2cm, bottom = 2cm]{geometry}
\usepackage[table,xcdraw]{xcolor}
\usepackage[document]{ragged2e}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
      \begin{axis}[
          width=4.5in,
          height=3.5in,
          scale only axis,
          xtick distance=1,
          ytick distance=1,
          %ymin=89,
          %ymax=98,
          xlabel=X,
          ylabel=Y
       ]
      \addplot[
          point meta=explicit symbolic,
          nodes near coords,
          scatter=true,
          only marks,
          mark=*,
          scatter/classes={
              A={mark=*,blue},
              B={mark=*,red}
          }
      ] table [x={x},y={y},meta=label] {
x    y     abc  label             
1.25 96.88 54.4 A
0.58 96.25 21.8 B
};
      \end{axis}
      \end{tikzpicture}
\end{document}
  • Yes, I want a legend with entries A and B, but programmatically – user106745 May 17 '22 at 13:02
  • See page 113 of the pgfplots manual for scatter plot legends. If you want to create your own legend, see https://tex.stackexchange.com/questions/54794/using-a-pgfplots-style-legend-in-a-plain-old-tikzpicture/148855?r=SearchResults&s=1%7C56.7928#148855 – John Kormylo May 17 '22 at 13:22

0 Answers0