4

I plot two time series with pgfplots in one chart. I have a legend in the top right corner. Now, I would like to add a label (saying "Correlation = 0.86") in the top left corner. I have tried a lot with nodes, but I did not succeed in placing them in the top left corner. Is it possible to do that without using coordinates?

1
  • It would be ideal if you could provide the community with something to play with in the form of a minimal working example (MWE).
    – Werner
    Commented Sep 9, 2015 at 21:15

2 Answers 2

4

You can use the rel axis cs coordinate system to add nodes with labels (rel axis cs:0,0) is the lower left corner of the plot, and (rel axis cs:1,1) is the upper right corner of the plot. A little example:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}
\addplot coordinates {(0,0) (1,10)}; 
\node[anchor=north west] at (rel axis cs:0,1) {Correlation ${}= 0.86$};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

To add the label outside the axis you'll need clip=false as axis option.

4
  • Doesn't it make more sense to use rel axis cs? Commented Sep 9, 2015 at 21:14
  • @TorbjørnT. It might depend. I added a note about this in any case. Commented Sep 9, 2015 at 21:17
  • Well, if one is after the top left corner, then I think it makes more sense, as you don't have to think about what the limits on the axes are. Commented Sep 9, 2015 at 21:20
  • @TorbjørnT. You're absolutely right! I had a mental lapsus. Will update immediately. Thnaks! Commented Sep 9, 2015 at 21:22
1

Another option is to give the axis environment a name, which you can refer to in the same way as other nodes.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[name=theaxis]
%\node[below left] at (rel axis cs:1,1) {Correlation${}= 0.86$};
\end{axis}
\node [below right] at (theaxis.north west) {Correlation${}= 0.86$};
\end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .