Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to produce a scatter plot from a data file. The data file could look like this:

 x       y       color   myvalue
 0.5     0.2     1       test
 0.2     0.1     2       uniform

I'd like to add the string data in column myvalue to the nodes, but still have the option to colour the marks. I tried two things recommended in the manual:

\begin{tikzpicture}
  \begin{axis}[% scatter/use mapped color={draw=black,fill=mapped color},
              enlargelimits=0.2]
    \addplot[scatter, mark=*,only marks, 
            scatter src=explicit symbolic,
            nodes near coords,]
      table [x=x, y=y, meta=myvalue] {tab.tbl};

   \end{axis}
\end{tikzpicture}

This allows me to put the labels to the marker in the plot.

first attempt

But I don't know how to add colours. My second attempt was to use the colour for the point meta data (manual page 88), but then I couldn't add text (it would only accept numbers in the code below):

\begin{tikzpicture}
  \begin{axis}[enlargelimits=0.2]
     \addplot[scatter, mark=*,only marks,
              scatter src=explicit symbolic,
           % we use ’point meta’ as color data...
           point meta=\thisrow{color},
           % ... therefore, we can’t use it as argument for nodes near coords ..
           nodes near coords*={\myvalue},
           % ... which requires to define a visualization dependency:
           visualization depends on={\thisrow{myvalue} \as \myvalue},
           ]
           table [x=x, y=y, meta=myvalue] {tab.tbl};
  \end{axis}
\end{tikzpicture}

How can I have both?

share|improve this question
add comment

1 Answer 1

oh, I found the solution in a related question.

How to use a string column to label datapoints in pgfplots.

The key is to use value in front of the macro definition.

The working code is:

\begin{tikzpicture}
  \begin{axis}[% scatter/use mapped color={draw=black,fill=mapped color},
              enlargelimits=0.2]
     \addplot[scatter, mark=*,only marks,
           % we use ’point meta’ as color data...
           point meta=\thisrow{color},
           % ... therefore, we can’t use it as argument for nodes near coords
           nodes near coords*={\myvalue},
           % ... which requires to define a visualization dependency:
           visualization depends on={value \thisrow{myvalue} \as \myvalue},
           ]
           table [x=x, y=y]
           {tab.tbl};
  \end{axis}

\end{tikzpicture}

colored

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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