1

Every post I've seen where they use pgfplot for plotting a log-log scale usually use a triangle to give the slope of the curve, something like the following:

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{spy}
\begin{document}

\begin{tikzpicture}[scale=1,spy using outlines={rectangle, magnification=5,connect spies}]         
    \begin{loglogaxis}[
        ymax=1,
        width = 7cm,
        legend style={at={(1,1)}, anchor=north east,draw=none},
    cycle list name=black white,
        every axis y label/.style={at={(current axis.west)},xshift=-40pt,rotate=90}
        ]

\addplot table[row sep=crcr]{%
20 0.6676955877494976\\
54 0.4421832562458617\\
170 0.3070095744635237\\
594 0.21570767663834237\\
2210 0.15213719464595102\\
8514 0.1074559581550062\\
3341 0 0.07594309310973704\\
}
   coordinate [pos=0.85] (A)
   coordinate [pos=0.95]  (B)
   ;
\draw[] (A) -| (B);
node [pos=0.95,anchor=west]{$2.0$};
\node at (B) [anchor=north] {$?$};    

   \end{loglogaxis}
\end{tikzpicture}

\end{document}

Is there an easy way to offset the triangle? I would like to indicate it as follows:

enter image description here

1

You can use the syntax provided by the calc library to calculate points shifted perpendicularly away from the line between A and B, and draw the triangle between those.

clip mode=individual was added so 0.272 wasn't clipped away.

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{spy,calc}
\begin{document}

\begin{tikzpicture}[scale=1,spy using outlines={rectangle, magnification=5,connect spies}]         
    \begin{loglogaxis}[
        ymax=1,
        width = 7cm,
        legend style={at={(1,1)}, anchor=north east,draw=none},
    cycle list name=black white,
        every axis y label/.style={at={(current axis.west)},xshift=-40pt,rotate=90},
        clip mode=individual
        ]

\addplot table[row sep=crcr]{%
20 0.6676955877494976\\
54 0.4421832562458617\\
170 0.3070095744635237\\
594 0.21570767663834237\\
2210 0.15213719464595102\\
8514 0.1074559581550062\\
3341 0 0.07594309310973704\\
}
   coordinate [pos=0.85] (A)
   coordinate [pos=0.95]  (B)
   ;

\coordinate (A') at ($(A)!3pt!90:(B)$);
\coordinate (B') at ($(B)!3pt!270:(A)$);
\draw  (A') -| (B') node[pos=0.25,above]{1} node[pos=0.75,right]{0.272};
\draw [shorten <=-3pt,shorten >=-3pt] (A') -- (B');
node [pos=0.95,anchor=west]{$2.0$};
\node at (B) [anchor=north] {$?$};    

   \end{loglogaxis}
\end{tikzpicture}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.