6

I have a file with 3 columns, space separated. The first two columns represent the center of a circle (x,y) and the last column is the circle radius.

I want to select every 4 rows (or more generally specifying row numbers in a list) and plot selected circles by a for loop.

I do not seem to work it out in pgfplotstable. Any hints?!

Thanks

2
  • 1
    Can you show the code you have so far?
    – Jake
    Commented Jul 8, 2013 at 11:09
  • I am reading pgfplotstable manual; I do not know how to pick up a row number and get its columns. If I have that I put \pgfplotstableread{data}\mydata; foreach i \in{1,4,8}{ get row i; \draw (axis cs:i1,i2) circle [radius=i3];}
    – eli
    Commented Jul 8, 2013 at 11:20

1 Answer 1

7

Here's a slightly adapted version of my answer to Drawing different tikz shapes parameterized by data from a file. It draws the circles using a scatterplots. You can choose to draw only every n-th mark using the mark repeat key, choosing which entry to start with using the mark phase key.

\documentclass{article}

\usepackage{pgfplots, filecontents}

\begin{filecontents}{data.dat}
# x y r
1 1 1
3 2 0.5
6 3 0.4
4 1 0.8
5 4 0.3
6 2 1
\end{filecontents}

\makeatletter
\begin{document}
\begin{tikzpicture}
\begin{axis}[scatter,
    scatter src=explicit,
    axis equal,
    only marks,
    grid=both,
    width=10cm,
    xmin=0, xmax=8,
    disabledatascaling,
    scatter/@pre marker code/.code={% Transform the data units to paper units
    \pgfkeys{/pgf/fpu=true}
      \pgfmathparse{(\pgfplotspointmeta*
        10^\pgfplots@data@scale@trafo@EXPONENT@x)*\pgfplots@x@veclength)}
      \pgfmathfloattofixed{\pgfmathresult}%
      \pgfkeys{/pgf/fpu=false}
      \scope[mark size=\pgfmathresult]
    }
]
\addplot [fill=yellow, mark repeat=2] file {data.dat};
\end{axis}
\end{tikzpicture}

\end{document}
2
  • oh! somehow those keys you used after xmax, do the trick; 'cause I do not see any circle command ! mark repeat is much better than x filter, Many thanks !
    – eli
    Commented Jul 8, 2013 at 11:54
  • The circles are drawn because the default plot marks in the axis environment are circles. You can change what shape to draw by setting mark=square* in the \addplot options, for example. The circles are selected using mark=*.
    – Jake
    Commented Jul 8, 2013 at 12:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .