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'm graphing part of a parabola, like so:

\documentclass{article}
\usepackage{tikz}

\begin{document}

    \begin{tikzpicture}
        \clip (-0.1,-0.1) rectangle (4,3);
        \draw[->] (0,0) -- (4,0);
        \draw[->] (0,0) -- (0,3);% draw axis lines
        \draw[domain=0.1:2,red,->,thick,samples=400] plot ({\x},{\x^3} );% draw plot
    \end{tikzpicture}

\end{document}

As you see, I'm trying to put an arrowhead onto the upward end of the parabola line, but it's not happening. I hypothesize that it's because the line is infinite, so there's no end to put an arrowhead on. Is that right? And in any case, is there a way to put an arrowhead on to that line?

share|improve this question
3  
The arrow was clipped (outside clipping box). Enlarge the clipping box, or shorten the domain to say 0.1:1 –  Kevin C Nov 25 '13 at 3:26
add comment

3 Answers

up vote 1 down vote accepted

In this case the TeX grouping braces are the source of error:

\documentclass{article}
\usepackage{tikz}

\begin{document}

    \begin{tikzpicture}
        \clip (-0.1,-0.1) rectangle (4,3);
        \draw[->] (0,0) -- (4,0);
        \draw[->] (0,0) -- (0,3);% draw axis lines
  %      \draw[domain=0.1:2,red,->,thick,samples=400] plot ({\x},{\x^3} );% draw plot
\draw[domain=0.1:2,red,->,thick,samples=400] plot (\x,\x^3 );% draw plot
    \end{tikzpicture}

\end{document}

If you choose:

\documentclass{article}
\usepackage{tikz}

\begin{document}

    \begin{tikzpicture}
      \clip (-0.1,-0.1) rectangle (4,3);
        \draw[->] (0,0) -- (4,0);
        \draw[->] (0,0) -- (0,3);% draw axis lines
  %      \draw[domain=0.1:2,red,->,thick,samples=400] plot ({\x},{\x^3} );% draw plot
\draw[domain=0.1:1.44,red,->,thick,samples=400]  plot (\x,\x^3 );% draw plot
    \end{tikzpicture}

\end{document}

(max about 1.44 instead of 2), you can see the arrowhead.

enter image description here

share|improve this answer
    
Removed braces; still no arrow. –  crmdgn Nov 25 '13 at 3:20
    
@crmdgn Please see an addidional remark. –  Przemysław Scherwentke Nov 25 '13 at 3:28
    
Found it. Fixed. –  crmdgn Nov 25 '13 at 10:40
add comment

I'd use pgfplots (which is based on tikz) for this purpose

screenshot

Here's some code to get you started- see the documentation and questions tagged with pgfplots on this site for more details.

% arara: pdflatex
\documentclass{standalone}

\usepackage{pgfplots}

% set the arrows as stealth fighters
\tikzset{>=stealth}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xmin=0,xmax=4,
    ymin=0,ymax=3,
    axis x line=middle,
    axis y line=middle,
    ]
    \addplot[->,domain=0:1.4,samples=100] expression {x^3};
  \end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
add comment

A recommended solution with PSTricks just for fun.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node,pst-plot}

\begin{document}

\begin{pspicture}[showgrid=false](-2,-4)(3,4)
\psplot[algebraic,linecolor=blue,arrows=->]{-1.5}{1.5}{x^3}
\psaxes[linecolor=gray]{->}(0,0)(-2,-3.5)(2.5,3.5)[$x$,0][$y$,90]
\end{pspicture}
\end{document}

enter image description here

share|improve this answer
    
The \psaxes can be drawn first to make the graph on the top. –  I am who I say I am Nov 25 '13 at 8:42
add comment

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.