I'd like to add annotations outside the plotting area, at the right axis, and at positions that depend on the coordinates of the plot.
I could do that with custom ticks, or adding nodes manually, but in the latter case I have to give the code in after end axis or disable clipping (which can have other undesirable effects, such as... not clipping). The best solution I've found so far is this:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\def\angs{0.529177208354}
\def\ev{27.2113838656}
\begin{axis}[
xmin = 2,
xmax = 4,
ymin = 0,
ymax = 5,
xlabel = {$r$},
ylabel = {$E$},
after end axis/.code = {
\path (axis cs:4.0,1.6) node[right] {B3LYP};
}
]
\def\ezero{-1.11}
\addplot+ table[x expr={\thisrowno{0}*2*\angs}, y expr={(\thisrowno{2}-\ezero)*\ev}] {data.dat};
\end{axis}
\end{tikzpicture}
\end{document}
It has to problems:
- I'd like to give the code next to
\addplot, and not in theaxisoptions. - I'd like the coordinates (in particular the ordinate) to be calculated automatically.
This shows the result with the following data.dat file:
2.0 -13840.8142382 -0.8142382
2.1 -13840.9230067 -0.9230067
2.2 -13840.9967745 -0.9967745
2.3 -13841.0454158 -1.0454158
2.4 -13841.0762998 -1.0762998
2.5 -13841.0944654 -1.0944654
2.6 -13841.1038383 -1.1038383
2.7 -13841.1070221 -1.1070221
2.8 -13841.1059849 -1.1059849
2.9 -13841.1022183 -1.1022183
3.0 -13841.0966277 -1.0966277
3.1 -13841.0899909 -1.0899909
3.2 -13841.0828688 -1.0828688
3.3 -13841.0755779 -1.0755779
3.4 -13841.0687860 -1.0687860
3.5 -13841.0626993 -1.0626993
3.6 -13841.0572297 -1.0572297
3.7 -13841.0527363 -1.0527363
3.8 -13841.0493218 -1.0493218
3.9 -13841.0467450 -1.0467450
4.0 -13841.0447949 -1.0447949
4.1 -13841.0433105 -1.0433105
4.2 -13841.0421877 -1.0421877
4.3 -13841.0413471 -1.0413471
4.4 -13841.0407159 -1.0407159
4.5 -13841.0402353 -1.0402353
4.6 -13841.0398710 -1.0398710
4.7 -13841.0395993 -1.0395993
4.8 -13841.0393960 -1.0393960
4.9 -13841.0392397 -1.0392397
5.0 -13841.0391747 -1.0391747

PS. Another question as a bonus: is there a way to use the numbers in the 2nd column, rather than the 3rd (which is just the 2nd + 13840), without losing precision?
