3

Καλημέρα!!

I 'm trying to draw a line with the angle of inclination, but nothing happens. What am I doing wrong?

\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

2 Answers 2

3

It is because you are running in the old compatibility mode. If you insist on this, you'd need to prepend axis cs: to your coordinates. However, I would like to argue that it is easier to switch to a newer version, which can be achieved by adding \pgfplotsset{compat=1.16}. (I also gave your angle the name \varphi, but of course you could go back to 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
  • Excellent!!! Thank's a lot!!! All working fine! P.S.: What is "compatibility mode"? Commented Dec 12, 2018 at 20:48
  • @ΚώσταςΚούδας There are various versions of pgfplots, which are not downward compatible. If you use pgfplots without setting any compat, it will use the original version. Later versions do no longer require to prepend axis cs: (and also have other advantages). BTW, if this answer worked for you, could you perhaps consider accepting it by clicking on the check mark left of it?
    – user121799
    Commented Dec 12, 2018 at 21:01
1

A PSTricks solution only for comparison purposes.

\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

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .