
y = 5 + x の線に平行に回転するノードを配置しようとしています。当然、回転角度は 45 度になると予想しました。
\documentclass[dvipsnames]{article}
\usepackage{pgfplots}
\usetikzlibrary{babel,calc,backgrounds,quotes,angles,patterns,decorations.markings,intersections,arrows,arrows.meta}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
xmin = -1,
ymin = -5,
xmax = 10,
ymax = 14,
domain = -1:10,
xtick = {1,2,...,9},
ytick = \empty,
xlabel style={below right},
ylabel style={above left},
x tick label style={below},
xlabel = {$x$},
ylabel = {$f$}
]
\addplot[very thick, domain=0:11] {5 + x};
\draw node[above,rotate=45] at (4, 9) {$v = v_0 + at$};
\end{axis}
\end{tikzpicture}
\end{document}
結果は次のとおりです。
さまざまな角度を試してみて、適切な角度を見つけました: 27。ただし、軸環境の ymin/ymax に依存します。ymin/ymax への自動修正を使用して、tikz でノードを直角 (つまり、線と平行) に描画するにはどうすればよいですか?
前もって感謝します
答え1
考えられる解決策は次のとおりです:
\documentclass[dvipsnames]{article}
\usepackage{pgfplots}
\usetikzlibrary{babel,calc,backgrounds,quotes,angles,patterns,decorations.markings,intersections,arrows,arrows.meta}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
xmin = -1,
ymin = -5,
xmax = 10,
ymax = 14,
domain = -1:10,
xtick = {1,2,...,9},
ytick = \empty,
xlabel style={below right},
ylabel style={above left},
x tick label style={below},
xlabel = {$x$},
ylabel = {$f$}
]
\addplot[very thick, domain=0:11] {5 + x};
\path (axis cs:0,5)-- node[above,sloped] {$v = v_0 + at$} (axis cs:9,14);
\end{axis}
\end{tikzpicture}
\end{document}