[Tex/LaTex] Fetch single data point from table within tikz

tikz-pgf

Let's say I have a bunch of data, like so:

1,15,53
5,74,12
74,23,66

It doesn't really matter how I store the data. I could put it in text form within my .tex file or I could store it in an external .csv file.

Now, I would like to fetch single data points within my tikz code. So, for example, let's say I wanted to use the data point at row 2, column 0 (which, in this case, is the number 74). My code would then look something like this:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}    
\node[draw] at (0,\dataPointAtRow2Column0) {test};
\end{tikzpicture}

Is there something I could write instead of \dataPointAtRow2Column0 to make tikz draw a node at (0,74)?

Note that I'm not looking for a solution like this. I do not want to rewrite my code using \pgfplots.

Best Answer

One possible way is to use pgfplotstable macro \pgfplotstablegetelem

\documentclass[border=2mm]{standalone}
\usepackage{pgfplotstable}
\pgfplotstableread[col sep=comma]{
1,15,53
5,74,12
74,23,66
}\mydata

\begin{document}
\begin{tikzpicture}
\node (o) at (0,0) {O};
\pgfplotstablegetelem{2}{0}\of\mydata
\node[draw] at (0,\pgfplotsretval pt) {test};
\end{tikzpicture}
\end{document}

enter image description here

Related Question