[Tex/LaTex] graph of arctan and arccot with tikz

plottikz-pgf

Please how to draw the graph of the inverse function of tangent and cotangent functions with TikZ:

$arctan: \mathbb{R}\to ]-\pi/2,\pi/2[$ and $arccot :\mathbb{R}\to ]0,\pi[$ 

with TikZ.

i want to obtain something like this for arctan

enter image description here

Best Answer

You do not need anything special in order to plot the inverse function of a known function f(x). To see this, recall that the plot of f(x) can be seen as a parametric plot of

 (x,f(x))

Call now x=f^{-1}(t). Then this plot will be

 (f^{-1}(t),t) .

From this it follows that a plot

 (f(t),t)

is the same as

 (t,f^{-1}(t)) 

where we have, of course, to adjust the domains appropriately. So in order to plot arctan(x) (the pgf name of the function is atan, see JairoAraujo' comment, or atan2, which takes care of the quadrant), we can just plot

 (tan(t),t)

and for arccot

 (cot(t),t) .

This is is illustrated in this MWE

\documentclass[tikz,border=3mm]{standalone}
\usepackage{amsmath}
\DeclareMathOperator{\arccot}{arccot}
\begin{document}
\begin{tikzpicture}[trig format=rad,samples=101]
\draw[blue,thick] plot[variable=\t,domain=-pi/2+0.1:pi/2-0.1] ({tan(\t)},\t);
\draw[red,dashed,thick] plot[variable=\t,domain=-10:10] (\t,{atan(\t)});
\path (8,pi/2) node[above]{$y=\arctan(x)$};
\draw plot[variable=\t,domain=-pi/2+0.1:-0.1] ({cot(\t)},\t);
\draw plot[variable=\t,domain=0.1:pi/2-0.1] ({cot(\t)},\t);
\path (8,0) node[below]{$y=\arccot(x)$};
\end{tikzpicture}
\end{document}

enter image description here

The dashed red curve is just to show that "it works".

Of course, it makes a lot of sense to plot this with pgfplots.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{amsmath}
\DeclareMathOperator{\arccot}{arccot}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[trig format plots=rad,
    samples=101,
    unbounded coords=jump,
    xmin=-10,xmax=10,ymax=pi/2+0.5
    ]
\addplot[blue,thick,variable=\t,domain=-pi/2+0.1:pi/2-0.1] ({tan(\t)},\t);
\path (10,pi/2) node[above left]{$y=\arctan(x)$};
\addplot[red,dashed,thick,variable=\t,domain=-10:10] (\t,{atan(\t)});
\addplot[green!60!black,variable=\t,domain=-pi/2+0.1:pi/2-0.1] ({cot(\t)},\t);
\draw[green!60!black,dashed] (0,-2) -- (0,2);
\path (10,0) node[below left]{$y=\arccot(x)$};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Or, per request without box and with a grid.

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\arccot}{arccot}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[axis lines=middle,xlabel={$x$},ylabel={$y$},
    width=0.9\textwidth,
    trig format plots=rad,
    samples=101,
    unbounded coords=jump,
    xmin=-pi,xmax=pi,
    ymin=-pi/2-0.2,ymax=pi/2+0.5,
    xtick={-pi/2,pi/2},xticklabels={$-\frac{\pi}{2}$,$\frac{\pi}{2}$},
    ytick={-pi/2,pi/2},yticklabels={$-\frac{\pi}{2}$,$\frac{\pi}{2}$},
    grid=major,grid style={densely dashed},
    legend style={at={(0.01,0.99)},anchor=north west}
    ]
\addplot[blue,thick,variable=\t,domain=-pi/2+0.1:pi/2-0.1] ({tan(\t)},\t);
\addlegendentry{$y=\arctan(x)$}
%\addplot[red,dashed,thick,variable=\t,domain=-10:10] (\t,{atan(\t)});
\addplot[green!60!black,variable=\t,domain=-pi/2+0.1:pi/2-0.1] ({cot(\t)},\t);
\draw[green!60!black,dashed] (0,-2) -- (0,2);
\addlegendentry{$y=\arccot(x)$}
\end{axis}
\end{tikzpicture}
\caption{``Standard'' branches of the multivalued functions $\arctan$ and $\arccot$.}
\end{figure}
\end{document}

enter image description here

Related Question