
Estoy dibujando varios diagramas como el siguiente:
Me gustaría etiquetar los puntos importantes con $P_1$
, $P_2$
etc. El problema es que no existe una posición global para la node
UE que se ajuste a todos.
No quiero que la etiqueta cubra la línea del diagrama.
- ¿Existe una forma inteligente de evitarlo?
- Puedo tener uncuarta columna(s, F, Etiqueta yPosición) con N(orth), W(est), S(outh) y E(ast), por ejemplo?
- ¿Tienes una buena idea?
Aquí está mi código hasta ahora:
\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},
]
\addplot[
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}
Respuesta1
Puedes usar
visualization depends on={value \thisrow{anchor}\as\myanchor},,
every node near coord/.append style={font=\small,anchor=\myanchor}
y agregue una cuarta columna con anclajes.
\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},
]
\addplot[
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}
Recuerda que también puedes utilizar ángulos como anclajes. Por ejemplo,
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\\
obras, donde el anclaje se especifica con ángulos dando total flexibilidad.