# How to draw tan(x) without pgfplot?

I want to know why output of the following MWE is ugly? i.e. yrange=-3:3 has no effect!!

\documentclass[12pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
\begin{tikzpicture}[domain=-4:4]
\draw[very thin,color=gray] (-0.4,-4) grid (4,4);
\draw[->] (-4.2,0) -- (4.2,0) node[right] {$x$};
\draw[->] (0,-4.2) -- (0,4.2) node[above] {$y$};
\draw[domain=-2*pi:2*pi, color=blue, samples=100, yrange=-3:3] plot[yrange=-3:3] (\x,{tan(\x r)}) node[right] {$f(x) = \tan x$};
\end{tikzpicture}
\end{document}

• This mean that range isn't like clip?
– user108724
Jan 27 '20 at 17:44
• can you explain where is its effect exactly?
– user108724
Jan 27 '20 at 17:46
• I think my above comment is not really to the point. yrange only has an effect if you plot the function with gnuplot. That is, you need the syntax plot plot[id=tan-example] function{tan(x)}.
– user194703
Jan 27 '20 at 18:14
• You can add \clip (-4,-3) rectangle (4,3); after the grid and labels are done. Jan 28 '20 at 16:16
• I know this and sorry for my question title. I want to know why yrange=-3:3 or range=-3:3 has no effect
– user108724
Jan 28 '20 at 16:39