# pgfplots: Pointwise Positioning of Explicit Point Meta

I am drawing several diagrams like the following one:

I would like to label the important points with $P_1$, $P_2$ and so on. The problem is that there is no global position for the nodes that fits for all.

I don't want that the label to cover the diagram line.

• Is there a clever way to avoid that?
• Can I have a fourth column (s, F, Label and Position) with N(orth), W(est), S(outh) and E(ast) for example?
• Have you a good idea?

Here's my code so far:

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
enlargelimits = true,
xlabel = {Travel $s$ in mm},
ylabel = {Force $F$ in N},
width =120mm,
height= 80mm,
title = {Force-Travel-Diagram},
]
line width=1pt,
mark=*,
x=s,
y=F,
nodes near coords,
point meta=explicit symbolic,
nodes={font=\small},
nodes near coords align={anchor=west},
] table
[
row sep=\\,
meta=Label
]
{
s F Label\\
0 0 {$P_0$}\\
0.03 2 {$P_1$}\\
0.7 6 {$P_2$}\\
0.71 5 {$P_3$}\\
1.4 12 {$P_4$}\\
};
\end{axis}
\end{tikzpicture}

\end{document}


You can use

visualization depends on={value \thisrow{anchor}\as\myanchor},,
every node near coord/.append style={font=\small,anchor=\myanchor}


and add a fourth column with anchors.

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
enlargelimits = true,
xlabel = {Travel $s$ in mm},
ylabel = {Force $F$ in N},
width =120mm,
height= 80mm,
title = {Force-Travel-Diagram},
]
line width=1pt,
mark=*,
x=s,
y=F,
nodes near coords,
point meta=explicit symbolic,
visualization depends on={value \thisrow{anchor}\as\myanchor},,
every node near coord/.append style={font=\small,anchor=\myanchor}
%nodes={font=\small},
%    nodes near coords align={anchor=west},
] table
[
row sep=\\,
meta=Label
]
{
s F Label anchor\\
0 0 {$P_0$} {south west}\\
0.03 2 {$P_1$} south\\
0.7 6 {$P_2$} south\\
0.71 5 {$P_3$} north\\
1.4 12 {$P_4$} west\\
};
\end{axis}
\end{tikzpicture}

\end{document}


Remember that you can also use angles as anchors. For example,

s F Label anchor\\
0 0 {$P_0$} 120\\
0.03 2 {$P_1$} 270\\
0.7 6 {$P_2$} 270\\
0.71 5 {$P_3$} 90\\
1.4 12 {$P_4$} 180\\


works, where anchor is specified with angles giving total flexibility.

• @ManuelKuehner: Meanwhile I have made some edits which you may like further. – user11232 Aug 1 '15 at 8:10
• Just perfect.Have a nice day! – Dr. Manuel Kuehner Aug 1 '15 at 9:02
• Just a luxury problem. The angle is always 180 degree wrong from what I want. I know why, because of the anchor. Is there a more intuitive syntax? Really not a problem. – Dr. Manuel Kuehner Aug 2 '15 at 9:26
• @ManuelKuehner I prefer exclusive anchors like east, south etc. – user11232 Aug 2 '15 at 12:23