0

I am trying to create a custom mark to use in a scatterplot. pgfplots: problem in the legend using custom marks has provided a hint on how to proceed but I do not know how to make this mark depend on a third variable. For example, the code below, is it possible to have \pgfdeclareplotmark get the \node label (which I have hard-coded with {a} below) from the label column in the data?

\documentclass{article}
\usepackage{pgfplots}\pgfplotsset{compat=1.16}
\usepackage{pgfplotstable}
\pgfplotstableread{
 y x label
 1 1     a
 2 2     b
 3 3     c
 }\testdata
 
\pgfdeclareplotmark{myshape} {\node[draw, rounded corners=2pt, color=blue, fill=white] {a};}

\begin{document}

\begin{tikzpicture}
\begin{axis}[]
  \addplot[ mark=myshape] table[x=x, y=y] {\testdata};
\end{axis}
\end{tikzpicture}

\end{document}

This is what I'd like to achieve with the labels. Thank you for any help.

enter image description here

2

Would it be an option to use nodes near coords instead?

enter image description here

\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.16}
\pgfplotstableread{
 y x label
 1 1     a
 2 2     b
 3 3     c
 }\testdata
 

\begin{document}

\begin{tikzpicture}
\begin{axis}
  \addplot[
     point meta=explicit symbolic,
     nodes near coords,
     nodes near coords align=center,
     nodes near coords style={draw, rounded corners=2pt, color=blue, fill=white}
     ] table[x=x, y=y, meta=label] {\testdata};
\end{axis}
\end{tikzpicture}

\end{document}
1
  • That's great, thank you Torbjørn
    – user20650
    Sep 19 '20 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.