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 have the following piece of code in my tex file.

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}[scale=2]
\tikzstyle{every node}=[font=\scriptsize]
\definecolor{mycolor1}{rgb}{0,0.5,0}

\begin{loglogaxis}[
ultra thick,
xshift=1.7in,
scale only axis,
width=1.2in,
height=1.25in,
xmin=2500, xmax=1000000,
ymin=1, ymax=1e7,
axis on top,
xlabel=Number of unknowns,
xlabel style={at={(0.125,-0.025)},anchor=south west},
ylabel=Time taken in seconds,
ylabel style={at={(0.22,0.125)},anchor=south west},
x tick label style={yshift=-3},
y tick label style={xshift=-2}]

\addplot [
color=red,
solid
]
coordinates{
(2500, 2)(10000, 6)(62500, 40)(250000, 155)(1000000, 600)
};

\addplot [
color=green,
solid
]
coordinates{
(2500, 52)(10000, 832)(62500, 32500)(250000, 520000)(1000000, 8320000)
};
\end{loglogaxis}
\end{tikzpicture}
\end{document}

The output is

enter image description here

I want to indicate on the figure that the red line is $10^4$ times faster than the green line by drawing an arrow between the two lines at the right extreme and writing $\times 10000$. How should I proceed?

Thanks

share|improve this question
    
A comment on your coding style, dont use \tikzstyle rather declare any styles within the \begin{tikzpicture}[<here>] or outside of the environment. (preferably using \tikzset which is consistent with \pgfkeys/\pgfplotsset). –  zeroth Oct 3 '12 at 19:22
    
@zeroth Ok. Thanks for the tip. –  user1876 Oct 3 '12 at 19:26
    
I changed the tags and title of your question to make clear that you are using the pgfplots package and expanded your code to full MWE. –  Benedikt Bauer Oct 3 '12 at 19:38
add comment

2 Answers

up vote 7 down vote accepted

There are more than one way of doing it but using the axis coordinate system seems the easiest for me.

\documentclass{standalone}
\usepackage{pgfplots}
\tikzstyle{every node}=[font=\scriptsize]
\definecolor{mycolor1}{rgb}{0,0.5,0}
\begin{document}
\begin{tikzpicture}[scale=2]    
\begin{loglogaxis}[
clip=false, %<---- Notice this option
ultra thick,
xshift=1.7in,
scale only axis,
width=1.2in,
height=1.25in,
xmin=2500, xmax=1000000,
ymin=1, ymax=1e7,
axis on top,
xlabel=Number of unknowns,
%xlabel style={at={(0.125,-0.025)},anchor=south west},
ylabel=Time taken in seconds,
%ylabel style={at={(0.22,0.125)},anchor=south west},
%x tick label style={yshift=-3},
%y tick label style={xshift=-2}
]

\addplot [color=red,solid]coordinates{(2500, 2)(10000, 6)(62500, 40)(250000, 155)(1000000, 600)};
\addplot [color=green,solid] coordinates{(2500, 52)(10000, 832)(62500, 32500)(250000, 520000)(1000000, 8320000)};
\draw[-latex,thick] (axis cs:2e6,1e3) -- (axis cs:2e6,1e7) node[right,midway] {$\times 10^4$};
\end{loglogaxis}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thanks!. This works fine for me. –  user1876 Oct 3 '12 at 19:55
    
Thanks @percusse. How do I move my arrow up or down as I want? –  user1876 Oct 3 '12 at 20:26
    
The arrow is following the axes for example (axis cs:2e6,1e3) is two million on x and a thousand on y if you change the y component the start point moves up and down. So in general, you change the coordinates. –  percusse Oct 3 '12 at 20:49
add comment

Another option is to place coordinates at the ends of the two plots and use those to draw the arrow, so the arrow will depend directly on the data.

Instead of using clip=false to allow the arrow to be shown outside the axis, you can use the after end axis/.code={...} key to define the \draw command. This has the advantage that the plots will still be clipped (if you reduce xmax, for instance), but the arrow will still be shown.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.5}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[
    scale only axis,
    width=1.2in,
    height=1.25in,
    xmin=2500, xmax=1000000,
    ymin=1, ymax=1e7,
    axis on top,
    xlabel=Number of unknowns,
    ylabel=Time taken in seconds,
    after end axis/.code={
        \draw [-latex] (A) -- (B) node [right,midway] {$\times 10^4$};
    }
]

\addplot [red,solid]
    coordinates {(2500, 2)(10000, 6)(62500, 40)(250000, 155)(1000000, 600)}     
    coordinate [xshift=1em] (A);
\addplot [green,solid]
    coordinates {(2500, 52)(10000, 832)(62500, 32500)(250000, 520000)(1000000, 8320000)}
    coordinate [xshift=1em] (B);
\end{loglogaxis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
Thanks Jake! How do I move my arrow up or down as I want? –  user1876 Oct 3 '12 at 20:21
    
@Marvis: Add a yshift=<length> to the two coordinate options in the \addplot command. –  Jake Oct 3 '12 at 21:07
    
Ah, nice detail with the after end axis. I should keep that in mind. –  percusse Oct 4 '12 at 13:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.