PGFPLOTS 中旋转标签的水平移动

PGFPLOTS 中旋转标签的水平移动

在下面的代码中,我在其中一个箭头处有一个长标签。我想将标签旋转 90 度,然后将其放置在箭头正下方。我使用选项rotatepos选项垂直旋转和移动标签。我怎样才能将标签水平移动到右侧,以便它显示在箭头正下方?

\documentclass[12pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
   scale=5,
   anchor=origin, 
   axis x line=middle,
   axis y line=middle,
   every axis x label/.style={at={(current axis.right of origin)},anchor=west},
   every axis y label/.style={at={(current axis.above origin)},anchor=south},
    enlarge x limits=0.05,
    enlarge y limits=0.1,
    xlabel=$x$,
    ylabel=$y$,
    x=1cm, y=1cm,
    xtick=\empty,
    ytick=\empty
    ]
\addplot [domain=-.5:1.65] {sin(deg(x))};
\draw[blue,->] (axis cs:pi/6,0.5)--(axis cs:pi/6,0) node[anchor=north, rotate=-90, pos=1.5]{$long-label$};
\draw[blue,->] (axis cs:pi/2,1)--(axis cs:pi/2,0) node[anchor=north]{$s_2$};
\end{axis} 
\end{tikzpicture}
\end{document}

enter image description here

答案1

改用anchor=west(不带pos; 默认为1.0)。并且不要对文本使用数学模式 (我不确定您的实际用例)。

完整的解释是:当rotate使用键时,节点的锚点(northsouth等)会随之旋转(也就是说,它是一个局部坐标变换)。因此,相对于主坐标系的“北”实际上位于west节点的旋转坐标系内。

\documentclass[12pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
   scale=5,
   anchor=origin, 
   axis x line=middle,
   axis y line=middle,
   every axis x label/.style={at={(current axis.right of origin)},anchor=west},
   every axis y label/.style={at={(current axis.above origin)},anchor=south},
    enlarge x limits=0.05,
    enlarge y limits=0.1,
    xlabel=$x$,
    ylabel=$y$,
    x=1cm, y=1cm,
    xtick=\empty,
    ytick=\empty
    ]
\addplot [domain=-.5:1.65] {sin(deg(x))};
\draw[blue,->] (axis cs:pi/6,0.5)--(axis cs:pi/6,0) node[anchor=west, rotate=-90]{long-label};
\draw[blue,->] (axis cs:pi/2,1)--(axis cs:pi/2,0) node[anchor=north]{$s_2$};
\end{axis} 
\end{tikzpicture}
\end{document}

enter image description here

相关内容