[Tex/LaTex] How to use data from a file in tikz

external filestikz-pgf

I am using TikZ and I want to produce several graphs from a data file. The file contains many lines with three numbers x y r. I want to use each line and draw a circle with \draw (\x,\y) circle(\r); where \x, \y and
\r have been assigned the values read on a line. Is there a way to make a \foreach-like loop to make this ? I could change the lines into x/y/z if necessary to run something like

\foreachline \x/\y/\r in {filename} {
   \draw (\x,\y) circle(\r);
}

Thanks

Best Answer

You could use something like datatool or csvsimple if you wanted:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.csv}
1, 2, 3
4, 5, 2
3, 1, 4
\end{filecontents*}
\usepackage{tikz,csvsimple}

\begin{document}

\csvreader[no head]{\jobname.csv}{1=\first, 2=\second, 3=\third}%
  {\tikz \draw (\first, \second) circle (\third);
    \par
    FYI, I used these numbers: \first, \second, \third.
    \par}

\end{document}
Related Question