Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've plotted a function using TikZ and gnuplot and would like to indicate certain points on the graph. From the manual, I can only figure out how to get TikZ to place a mark at a point it's using to plot the function. Is there a clever (or even a simple) way to do this or am I better off just making a node for each point I want?

For reference, so far I have

\begin{tikzpicture}[domain=-4:4]
    \draw[very thin,color=gray] (-4.1,-1.1) grid (3.9,0.9);       
      \draw[color=red] plot[id=f,smooth] function{x*exp(-2*x**2)}
        node[right]{$f(x)=xe^{-2x^2}$};
\end{tikzpicture}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

I still have a long way to go in TikZ but I will try to answer your question. If you already know the coordinates you would like to mark on your graph, you could simply use the foreachcommand in this way:

\foreach (\x,\y) in {(x1,y1), (x2,y2), ...}
   \filldraw[] (\x,\y) circle () node[] {$(\x,\y)$}; 
However, I am guessing you probably want to mark points along the function, so maybe the above is not that useful. In that case you may want to try:

\foreach \x in { x1, x2, ...}
  \filldraw[] ( \x, {\x*exp( -2*(\x^2) )} ) circle (); 

You may notice that I have written your function in PGF math syntax. I use the PGF math engine, as opposed to gnuplot but the code should still work perfectly on your present graph.

share|improve this answer
    
Thanks, your second idea was what I was after, particularly incorporating the function into the for loop (let's just ignore the fact I forgot for loops exist despite there being a bunch in the document already). –  hoyland Dec 10 '10 at 3:33

Your Answer

 
discard

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.