[Tex/LaTex] Nodes near coord overlapping…how to shift up

nodes-near-coordspgfplots

enter image description here

I am using nodes near coords but as you can see the values on the bottom are overlapping. I have tried placing them manually but that hasn't worked either…How to just shift up the nodes so they do not overlap with eachother or the line!?

Thank you!!!!!

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{decorations.markings}
\begin{document}



\begin{tikzpicture}

    \begin{axis}[
compat=newest, 
height=0.4\textheight,
enlarge y limits={upper, value=0.3},
ymin=0,
xtick=data,
xtick={\empty},
ytick=data,
enlarge x limits = 0.5,
bar width=24pt,
title={},
symbolic x coords={0,5},
y axis line style={opacity=0},
yticklabels={\empty},
ytick style={draw=none},
axis on top,
major grid style=white,
nodes near coords
        ]

\addplot [red, line width=2pt]coordinates {(0,.1) (5,.83)};
\addplot [blue, line width=2pt]coordinates {(0,.12) (5,2.4)};
\end{axis}
\end{tikzpicture}
\end{document}

Best Answer

This is one possible solution. Firstly, move every node near coords down a little bit via

every node near coord/.append style={yshift=-0.5cm}   % yshift can be adjusted

Then adds to the addplot[options] a particular nodes near coords (the blue one) via raisebox

nodes near coords=\raisebox{0.7cm}{\pgfmathprintnumber\pgfplotspointmeta}  % 0.7 can be adjusted also.

The result is shown below

enter image description here

Code

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{decorations.markings}
\begin{document}

\begin{tikzpicture}

\begin{axis}[
compat=newest, 
height=0.4\textheight,
enlarge y limits={upper, value=0.3},
ymin=0,
xtick=data,
xtick={\empty},
ytick=data,
enlarge x limits = 0.5,
bar width=24pt,
title={},
symbolic x coords={0,5},
y axis line style={opacity=0},
yticklabels={\empty},
ytick style={draw=none},
axis on top,
major grid style=white,
nodes near coords,
every node near coord/.append style={yshift=-0.5cm},
        ]
\addplot [red, line width=2pt] coordinates {(0,.1) (5,.83)};
\addplot [blue, line width=2pt,
nodes near coords=\raisebox{0.7cm}{\pgfmathprintnumber\pgfplotspointmeta}
]
coordinates {(0,.12) (5,2.4)};
\end{axis}
\end{tikzpicture}
\end{document}