如何旋转节点以使其与线平行?

如何旋转节点以使其与线平行?

我正在尝试将一个节点旋转到与直线 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。如何让 tikz 以直角绘制节点(因此它与线平行)并自动校正 ymin/ymax?

提前致谢

答案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}

在此处输入图片描述

相关内容