TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have written this code and it works:

\foreach \columna in {1,3,...,\DTLcolumncount{DBcurva}}{
    \foreach \fila in {1,2,...,\DTLrowcount{DBcurva}}
      \xdef\listaPuntos{(\cX,\cY) -- \listaPuntos}
    \draw \listaPuntos cycle;

This reads a CSV file called "Curvas.csv". The columns are coordinates of points on curves (X1,Y1,X2,Y2,X3,Y3,X4,Y4..). The code draws all the curves in the file (initially I don't know how many there are) without problems.

Is there a better way (I can't separate each curve in different files)?

share|improve this question
up vote 7 down vote accepted

You could use pgfplots to loop through the columns in your datafile and draw the curves:




\begin{axis}[every plot/.style={no markers},cycle list name=linestyles]
\pgfplotstableread[col sep=comma] {testdata.csv}\data % Save the CSV to a macro
\pgfplotstablegetcolsof{\data} % Get the number of columns n
\pgfmathparse{\pgfplotsretval-2} % Calculate column index Xn = n-2

\foreach \x in {0,2,...,\xmax} {
    \pgfmathadd{\x}{1} % Offset one to get Y column index
    \addplot+[no markers,line width=2pt] table [x index=\x,y index=\y] \data;




enter image description here

share|improve this answer
Thanks a lot, it's a lot faster !! – Fernando Nadal Jan 27 '11 at 18:11
@Fernando: If this answers is what you want, please accept it by using the tick-mark symbol below the voting arrows. This way your question is removed from the "unanswered question" section and Jake gets some points as rewards. You should also up-vote correct answers if you not already did that. Thanks! – Martin Scharrer Mar 2 '11 at 16:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.