[Tex/LaTex] Drawing different tikz shapes parameterized by data from a file

external filestikz-pgf

I have a file with three columns of data, x, y, r.

# x y r
1 1 0.1
2 2 0.5
3 3 1.2

and so on. I'd like to loop over the rows, and draw a circle at x,y with radius r for each row.

I first thought I'd use pgfplots with customized marks, but I couldn't figure out how to pass the radius parameter into the pgfplot mark handler. Then I thought I'd use tikz and pgf directly, but I couldn't figure out how to reference the values for r inside a draw command sequence.

Any thoughts ? I'd be very grateful for some help.

Best Answer

Another option is to use the datatool package.

\documentclass[a4paper]{scrartcl}
\usepackage{datatool,tikz}
\DTLloaddb[noheader=false]{coordinates}{coord.dat}

\begin{document}
\begin{tikzpicture}
\DTLforeach*{coordinates}{\x=x, \y=y, \r=r}{\draw (\x,\y) circle (\r);}
\end{tikzpicture}
\end{document}

where coord.dat is a comma separated file with header row, e.g.

x,y,r
2,1,0.1
3,2,0.5
1,3,1.2