倾斜角度

倾斜角度

嘎嘎!!

我试图绘制一条具有倾斜角度的线,但什么也没发生。我做错了什么?

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz,pgfplots}

\usetikzlibrary{calc,patterns,angles,quotes}

\begin{document}
    \begin{tikzpicture}[>=latex]
            \begin{axis}[
    ticks=none,
    axis x line=center,
    axis y line=center,
    xlabel={$x$},
    ylabel={$y$},
    xlabel style={below right},
    ylabel style={above left},
    xmin=-2,
    xmax=2,
    ymin=-0.5,
    ymax=3]
    \addplot [domain=-2:2,ultra thick] {2*x+1} node [pos=0.95, below left] {$C_f$};
    \coordinate (A) at (0,1);
    \coordinate (B) at (-0.5,0);
    \coordinate (C) at (5,0);
    \pic [draw, ->, "angle name", angle radius=1, angle eccentricity=1.5] {angle = C--B--A};
            \end{axis}

    \end{tikzpicture}
\end{document}

答案1

这是因为您运行的是旧兼容模式。如果您坚持这样做,则需要axis cs:在坐标前添加。但是,我想说的是,切换到较新的版本更容易,只需添加 即可\pgfplotsset{compat=1.16}。(我还为您的角度指定了 名称\varphi,但您当然可以返回angle name。)

\documentclass{article}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{calc,patterns,angles,quotes}

\begin{document}
    \begin{tikzpicture}[>=latex]
            \begin{axis}[
    ticks=none,
    axis x line=center,
    axis y line=center,
    xlabel={$x$},
    ylabel={$y$},
    xlabel style={below right},
    ylabel style={above left},
    xmin=-2,
    xmax=2,
    ymin=-0.5,
    ymax=3]
    \addplot [domain=-2:2,ultra thick] {2*x+1} node [pos=0.95, below left] {$C_f$};
    \coordinate (A) at (0,1);
    \coordinate (B) at (-0.5,0);
    \coordinate (C) at (5,0);
    \pic [draw, ->, "$\varphi$", angle radius=1cm, angle eccentricity=1.5] 
    {angle = C--B--A};
            \end{axis}

    \end{tikzpicture}
\end{document}

enter image description here

答案2

PSTricks 解决方案仅用于比较目的。

\documentclass[pstricks,border=1pt]{standalone}
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}(-2,-1)(1.4,3.4)
\psaxes[ticks=none,labels=none]{->}(0,0)(-2,-1)(1,3)[$x$,0][$y$,90]
\psplot[algebraic]{-1.4}{.4}{2*x+2}
\psarc{->}(-1,0){.7}{0}{!2 1 atan}
\uput{.3}[!2 1 atan 2 div](-1,0){$\varphi$}
\end{pspicture}
\end{document}

enter image description here

相关内容