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 would create a scatter plot using pgfplots using data from my dat file that contains this data:

nodes     x         y       label

1.0000    14.1209   7.0332  a

2.0000     0.6367   16.6166 a

3.0000     5.5385   11.7053 a

4.0000     0.9234   10.9945 a

5.0000     1.9426   18.3439 b

6.0000    16.4692    5.7168 b

7.0000    13.8966   15.1440 a

8.0000     6.3420   15.0746 a

9.0000    19.0044    7.6089 b

10.0000    0.6889   11.3564 b

I would create a scatter plot where the first column is the label of every scatter while the two next colomn are x and y. The last column is a class that decide if the scatter has to be red or blue This is the code I had created

 \begin{figure}
\centering
\begin{tikzpicture}
    \begin{axis}[xlabel=metri,ylabel=metri]
        \addplot[nodes near coords*={\thisrow{nodes}},
            scatter/classes={
                a={mark=*,blue},
                b={mark=*,red}
                },
                scatter, only marks,
                scatter src=explicit symbolic]
         table[x=x,y=y,meta=label]
            {./MATLAB/grafici/network_map.txt};
    \end{axis}
\end{tikzpicture}

\end{figure}

Unfortunately in this way I don't get the label. Something doesn't work

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

Since you are using meta info for colors, you need to use visualization depends on for the remaining data. And it should come after the scatter src option otherwise it will be overwritten.

\documentclass{article}
\usepackage{pgfplots,filecontents}
\pgfplotsset{compat=1.7}
\begin{filecontents*}{mydata.dat}
nodes     x         y       label
1.0000    14.1209   7.0332  a
2.0000     0.6367   16.6166 a
3.0000     5.5385   11.7053 a
4.0000     0.9234   10.9945 a
5.0000     1.9426   18.3439 b
6.0000    16.4692    5.7168 b
7.0000    13.8966   15.1440 a
8.0000     6.3420   15.0746 a
9.0000    19.0044    7.6089 b
10.0000    0.6889   11.3564 b
\end{filecontents*}

\begin{document}

 \begin{figure}
\centering
\begin{tikzpicture}
    \begin{axis}[xlabel=metri,ylabel=metri]
        \addplot[
                visualization depends on={\thisrow{nodes}\as\myvalue},
            scatter/classes={
                a={mark=*,blue},
                b={mark=*,red}
                },
                scatter, only marks,
                scatter src=explicit symbolic,
                nodes near coords*={\pgfmathprintnumber[int detect]\myvalue},]
         table[x=x,y=y,meta=label]
            {mydata.dat};
    \end{axis}
\end{tikzpicture}

\end{figure}
\end{document}

enter image description here

share|improve this answer
    
Does it exist a way to get label smaller? –  Mazzy Dec 12 '12 at 2:14
1  
@Mazzy You can add \tiny or \small before the \pgfmathprintnumber –  percusse Dec 12 '12 at 2:26
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.