4

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

7

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}
  • @Tom-Tom -- Cheers! – jon Oct 3 '15 at 20:53

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.