# TikZ Issue With Function Plotting

I am trying to create this simple TikZ plot of a quadratic function. But the code does not compile, and the error is detected at the part where I introduce the function. What is wrong with it?

\begin{tikzpicture} [xscale=1,yscale=1]

\draw [->] (0,0) -- (0,2) node [left,pos=1] {$\Delta x$} node [above right] at (0.5,2) {Car};
\draw [->] (0,0) -- (2.1,0) node [below, pos=0.9] {$\Delta t$};
\draw [domain=0:2] plot (\x, {2.5\x*\x});

\end{tikzpicture}


Furthermore, how is it possible to put two TikZ plots side by side on the same line? I have not been able to do this so far.

Thanks!

Welcome to TeX SE! Next time, please post a complete minimal working example (MWE).

You are missing an *:

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture} [xscale=1,yscale=1]

\draw [->] (0,0) -- (0,2) node [left,pos=1] {$\Delta x$} node [above right] at (0.5,2) {Car};
\draw [->] (0,0) -- (2.1,0) node [below, pos=0.9] {$\Delta t$};
\draw [domain=0:2] plot (\x, {2.5*\x*\x});% missing *

\end{tikzpicture}
\end{document}


# EDIT

To stop the function exceeding certain boundaries without having to recalculate the domain, you could clip the plot:

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture} [xscale=1,yscale=1]
\draw [->] (0,0) -- (0,2) node [left,pos=1] {$\Delta x$} node [above right] at (0.5,2) {Car};
\draw [->] (0,0) -- (2.1,0) node [below, pos=0.9] {$\Delta t$};
\begin{scope}
\clip (0,0) |- (2.1,2) |- cycle;
\draw [domain=0:2] plot (\x, {2.5*\x*\x});
\end{scope}
\end{tikzpicture}
\end{document}


You can adjust the clipping path if you want slightly different restrictions.

• Great, thanks! I will be sure to post a MWE next time. Also, could you please answer the other part of the question? – user11629 Sep 8 '14 at 1:31
• @user11629 See edited answer. – cfr Sep 8 '14 at 1:38
• What does the word "cycle" perform in this? And if you put two plots side by side, is there a command to line them up? at the bottom axes? – user11629 Sep 8 '14 at 1:46
• cycle is just shorthand for 'and back to wherever this path started'. So it completes the rectangle. I could have repeated the first coordinate instead. Probably the two plots question should be a new question so that you can include code for two plots. – cfr Sep 8 '14 at 2:05