# TikZ/PGF: Simple function is not plotted. Where is the mistake?

I'm just starting to learn TikZ/PGF. I would like to draw a simple function, f(x) = x² to start with.

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}

\draw [thick, domain=0:1] plot  (\x,  {\x*\x});

\end{axis}
\end{tikzpicture}
\end{document}


This is the most minimal example I can think of. Substituting the \x*\x with something else to exclude a syntax error does not work either. Where am I making the mistake?

-

## 2 Answers

Change \draw [thick, domain=0:1] plot (\x,{\x*\x}); to \addplot [thick, domain=0:1] (\x,{\x*\x}); and it should work fine

-
Thanks a lot, what a stupid mistake. –  Eekhoorn Aug 3 '12 at 9:33
No worries, we all make simple mistakes at the beginning. And you'll learn more by it...Claudio's answer is probably more insightful though as it explains the mix up. –  Leeser Aug 3 '12 at 9:37

I think you are mixing the syntax from both TikZ and pgfplots. Basically, if you want to use pgfplots, you need to call \addplot inside the axis environment, while when using TikZ you simply need the standard \draw command with plot.

Here you find two basic examples in both cases with your function:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
Using just Ti\emph{k}Z:
\begin{center}
\begin{tikzpicture}[ domain=0:1]
\draw[very thin,color=gray] (-0.1,-1.1) grid (1.9,1.9);
\draw [thick,] plot  (\x,\x*\x);
\end{tikzpicture}
\end{center}
\vspace{2cm}
Using pgfplots:
\begin{center}
\begin{tikzpicture}[domain=0:1]
\begin{axis}
\addplot {x*x};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}


Result:

Notice that in my example I just loaded pgfplots since it automatically loads TikZ.

-