
Я рисую несколько диаграмм, подобных следующей:
Я хотел бы пометить важные точки как $P_1$
и $P_2$
т. д. Проблема в том, что не существует глобальной позиции для node
s, которая подходила бы всем.
Я не хочу, чтобы этикетка закрывала линию диаграммы.
- Есть ли какой-нибудь разумный способ этого избежать?
- Могу я иметьчетвертая колонка(s, F, Метка иПозиция) например, с С(север), З(вест), Ю(юг) и В(восток)?
- У вас есть хорошая идея?
Вот мой код на данный момент:
\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}
решение1
Вы можете использовать
visualization depends on={value \thisrow{anchor}\as\myanchor},,
every node near coord/.append style={font=\small,anchor=\myanchor}
и добавьте четвертый столбец с якорями.
\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}
Помните, что вы также можете использовать углы в качестве якорей. Например,
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\\
работы, где анкер задается с углами, обеспечивающими полную гибкость.