UPDATE: A little research reveals that this question has already been asked here, but the answer suggests that it doesn't really work. In more detail, min value=-4 and max value=4 are supported, but they prevent the plot not from overshooting, as mentioned in the pgfmanual in section 77.2.3. I also started to play with the at start survey keys and the like, attempting to clip on the data visualization bounding box. Yet this was not successful. So in the end the only thing I can offer here is the very ad hoc way to confine the tan plot is to plot max(min(tan(\value x r),4),-4) instead, which only takes values between -4 and 4. As I mentioned above, r converts radians into degrees.
\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\begin{tikzpicture}
\datavisualization [scientific axes=clean,
y axis={grid,min value=-4,max value=4},
visualize as smooth line/.list={sin,cos,tan},
style sheet=strong colors,
style sheet=vary dashing,
sin={label in legend={text=$\sin x$}},
cos={label in legend={text=$\cos x$}},
tan={label in legend={text=$\tan x$}},
data/format=function,
% at start survey={\clip (data visualization bounding
% box.south west) rectangle (data visualization bounding box.north east);}
]
data [set=sin] {
var x : interval [-0.5*pi:4];
func y = sin(\value x r);
}
data [set=cos] {
var x : interval [-0.5*pi:4];
func y = cos(\value x r);
}
data [set=tan] {
var x : interval [0:4];
func y = max(min(tan(\value x r),4),-4);
};
\end{tikzpicture}
\end{document}
Perhaps someone else can make the commented out bit work....
sinetc. to be degrees, and as you can see from the plots,rconverts radians to degrees. – Feb 23 '18 at 16:51