10

Is there (I'm sure there must be) a way to use meta data for markers?

I have something like the below:

Year              coeff        meta
2005               1.2183       o
2006               0.1073       star
2007               0.5629       square
2008               1.0168       diamond
2009               -4.4083      otimes

And I'd like a scatter plot that uses meta data for the markers.

Thanks!

10

You can make the contents of the meta column available by adding point meta=explicit symbolic to the \addplot options, where the explicit indicates that the meta data is distinct from the y coordinate (by default, the y coordinate is used as the meta data), and the symbolic indicates that the values shouldn't be parsed as numbers.

Then you can use the scatter/@pre marker code to set the mark depending on the content of the meta variable:

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots, pgfplotstable}

\begin{document}

\begin{tikzpicture}
\begin{axis}[/pgf/number format/1000 sep={}]
\addplot [
    point meta=explicit symbolic,
    scatter, only marks,
    scatter/@pre marker code/.code={\pgfplotsset{mark=\pgfplotspointmeta}},
    scatter/@post marker code/.code={}
] table [meta=meta] {
Year              coeff        meta
2005               1.2183       o
2006               0.1073       star
2007               0.5629       square
2008               1.0168       diamond
2009               -4.4083      otimes
};
\end{axis}
\end{tikzpicture}

\end{document}

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.