# Marking Specific x-values in TikZ Plot

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}

-

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.

-
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