Given some data from a file, I would like to use the first two columns as coordinates, and the second two columns as label for every point. The data is given in this form:
x y labela labelb
1.416197036356566059e+02 5.144315570548267715e+03 7.000000000000000000e+00 1.000000000000000000e+00
I use the table
command to read the first two columns as data:
\begin{tikzpicture}
\begin{axis}
\addplot+[only marks,x=x, y=y, ] table {DataTable.dat};
\end{axis}
\end{tikzpicture}
The data of the second column should appear above each scatter point as simple text or may be in a bubble like this: labela / labelb
.
A promising option seems to be the option nodes near coords
which I use to show the y-coordinate of points in other plots, but I don't see how I can use the data from the file and combine it with that.
Best Answer
nodes near coords
is the right approach. You can make your two label columns available inside the label nodes using the keyvisualization depends on=\thisrow{<column name>} \as \<macro name>
. The key can be called as often as you like.Then, you can typeset the labels using
nodes near coords=\pgfmathprintnumber{\<macronameA>} / \pgfmathprintnumber{\<macronameB>}
. The styles for the label nodes can be set usingevery node near coord/.append style=<styles>
.Note that the label nodes will not automatically increase the axis limits, so they might overlap the axes. In that case, you'll need to use
enlargelimits
orenlarge y limits
.