I have a csv file consisting of two columns corresponding to the x and y coordinates of a point cloud. Since it is possible to label a point in a tikzpicture environment by

\coordinate (1) at (0,0); # from now one simply has to write (1) instead of (0,0)

I was wondering if it is possible to import the points from the csv file and labeling them automatically with their appropriate row number in the file.

  • Yes that's what pgfplots does. You can also use plot from TikZ – percusse Nov 3 '17 at 0:18

Here, I use readarray to absorb and compose the data. I label the coordinates as R\i where \i is the local row number.

0, 0
1, 1
2, 4
3, 9
\def\thedamnedline{}% INITIALIZE
\foreach\i in {1, ..., \xyptsROWS}{
  \coordinate[label=\textcolor{red}{R\i}](R\i) at (\xypts[\i,1],\xypts[\i,2]);% DEFINE/LABEL
  \fill[red] (R\i) circle (2pt);% ADD CIRCLE AT EACH COORDINATE
  \ifnum\i>1\relax\xdef\thedamnedline{\thedamnedline -- }\fi% COMPOSE INTERCOORDINATE LINKS
  \xdef\thedamnedline{\thedamnedline (R\i) }% COMPOSE COORDINATES SEQUENTIALLY FOR LINE
\draw\thedamnedline;% DRAW \thedamnedline (PREVIOUSLY COMPOSED)

enter image description here


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.