3

I want to print a scatter chart and color the nodes according to a column in the data file. The problem is, point meta already is used for other data. This is the class of the point, either ONE or TWO, it is used for the mark. Also, the nodes are labeled.

So how to do this?

Working example:

\input{include_filename} % defines \outputfile, written by batchjob
\documentclass[border=5pt,convert]{standalone}
\usepackage[english]{babel}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\pgfplotsset{compat=1.10}
\begin{document}%
    \setlength{\textwidth}{500pt}%
    \setlength{\linewidth}{500pt}%
\begin{tikzpicture}
\begin{axis}[]
\addplot+[
    scatter, only marks,
    point meta=explicit symbolic,
    scatter/classes={
        ONE={mark=*,mark color=\myerror},%             <-- here is the problem
        TWO={mark=triangle*,mark color=\myerror}},%
    nodes near coords*={\pgfmathprintnumber[int detect]{\myindex}},
    visualization depends on={\thisrow{error} \as \myerror},
    visualization depends on={\thisrow{index} \as \myindex},
]
    table[meta=partition]{\outputfile};     
\end{axis}
\end{tikzpicture}
\end{document}

Scatter chart

The datafile looks like this:

x   y   error   partition   index
-86 -27 0   ONE 3

error might be quite a large negative number. Like -35547923 e.g.

4

If I understand correctly, your marker color should be taken from a color map, right?

I believe a simple solution would be to use error as input for point meta. That way, you get the mapping into the color map for free. Of course, we will need to use a different key to satisfy scatter/classes. My idea is that we simply exchange the value of point meta right before scatter/classes reads it:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\begin{document}%

\begin{tikzpicture}
\begin{axis}[]

\addplot+[
    scatter, only marks,
    point meta=\thisrow{error},
    % use this key merely to define 'mapped color' based on the error
    % value. The '{}' overrides the default 'draw' and 'fill' options
    % of 'use mapped color':
    scatter/use mapped color={},
    % now, append code which RESETS \pgfplotspointmeta to \partition.
    % This will become the input to 'scatter/classes*':
    scatter/@pre marker code/.append code={%
        \let\pgfplotspointmeta=\partition
    },%
    scatter/classes*={
        ONE={mark=*,mapped color},%
        TWO={mark=triangle*,mapped color}},%
    nodes near coords*={\pgfmathprintnumber[int detect]{\myindex}},
    %
    % use 'value ' here : partition should not be parsed as number.
    visualization depends on={value \thisrow{partition} \as \partition},
    visualization depends on={\thisrow{index} \as \myindex},
]
    table[meta=partition]{
        x   y   error   partition   index
        -86 -27 0   ONE 3
        -0 -100 -15547923   ONE 42
        50 -200 -35547923   TWO 4
    };     
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

The /.append code does the same as scatter/classes* and nodes near coords*: it appends code to pre marker code. Since these are applied in the specified order, we can reset point meta in-between.

| improve this answer | |
  • Thanks to the author of pgfplots, the documentation is really great and full of good examples! – sinned Aug 23 '14 at 11:06
  • Thanks for the praise! I am glad pgfplots proves to be useful. – Christian Feuersänger Aug 23 '14 at 12:35

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.