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.

In my plot, I want to indicate the direction of a graph with arrows.

Usually, I would just create something like this:

\begin{tikzpicture}
    \begin{axis}[
        axis x line=center,
        axis y line=center,
        xmax=3.5,xmin=-4,
        ymax=6,ymin=-4,
        xlabel=$x_1$,
        ylabel=$x_2$,
        xtick=\empty,ytick=\empty
        ]
    \addplot[smooth,domain=-3.5:2.7,mark=none,black]{-(x/1.5+0.1)^2 + 2};
    \pgfmathsetmacro{\arronestart}{-(-0.6/1.5+0.1)^2+2};
    \pgfmathsetmacro{\arroneend}{-(-0.59/1.5+0.1)^2+2};
    \draw[
     decoration={markings,mark=at position 1 with {\arrow[ultra thick]{stealth}}},
     postaction={decorate}
     ] (axis cs:-0.6,\arronestart) -- (axis cs:-0.59,\arroneend);
    \pgfmathsetmacro{\arrtwostart}{-(2.69/1.5+0.1)^2+2};
    \pgfmathsetmacro{\arrtwoend}{-(2.7/1.5+0.1)^2+2};
    \draw[
     decoration={markings,mark=at position 1 with {\arrow[ultra thick]{stealth}}},
     postaction={decorate}
     ] (axis cs:2.69,\arrtwostart) -- (axis cs:2.7,\arrtwoend);
    \end{axis}
\end{tikzpicture}

Now, what I would like to have is a legend entry for those arrows, something like: ->- , but of course this is not possible with \draw[] ;. So, is there a way to have arrows as markings, so that I can create the same graph just using \addplot instead of \draw and have a proper legend?

share|improve this question
    
Do graphs have directions? –  Thorsten Donig Jul 31 '11 at 10:34
    
I am not sure, but I think they don't. –  mSSM Jul 31 '11 at 14:07

1 Answer 1

up vote 3 down vote accepted

You can use the \addlegendimage command to document custom draw statements:

        \draw[red,->] (axis cs:0,1) -- (axis cs:1,2);
    \addlegendimage{red,->}
    \addlegendentry{Something}

Here, the \addlegendimage provides the options to visualize the legend entry and \addlegendentry provides the text.

share|improve this answer
    
Great, that really helps. Thank you! –  mSSM Jul 31 '11 at 23:23

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.