PGFPLOTS 中旋轉標籤的水平移動

PGFPLOTS 中旋轉標籤的水平移動

在下面的程式碼中,我在其中一個箭頭處有一個長標籤。我想將標籤旋轉 90 度,然後將其放置在箭頭的正下方。我使用了rotate選項和pos垂直旋轉和移動標籤的選項。如何將標籤水平向右移動,使其顯示在箭頭的正下方?

\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}

在此輸入影像描述

答案1

改為使用anchor=west(不含pos;預設為1.0)。並且不要對文字使用數學模式(我不確定您在這裡的實際用例)。

完整解釋:當rotate使用 key 時,節點的錨點(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}

在此輸入影像描述

相關內容