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)?


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

  • @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 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.