TransWikia.com

Let custom mark depend on a variable

TeX - LaTeX Asked by user20650 on February 12, 2021

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

One Answer

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}

Answered by Torbjørn T. on February 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP