I want to plot few functions with tikz. Values of some of them grows too huge. In tikz manual there is an example with "nice" functions that do not grow too much:

```
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[domain=0:4]
\draw[very thin,color=gray] (-0.1,-1.1) grid (3.9,3.9);
\draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$};
\draw[color=red] plot (\x,\x) node[right] {$f(x) =x$};
\draw[color=blue] plot (\x,{sin(\x r)}) node[right] {$f(x) = \sin x$};
\draw[color=orange] plot (\x,{0.05*exp(\x)}) node[right] {$f(x) =q\frac{1}{20} \mathrm e^x$};
\end{tikzpicture}
\end{document}
```

How to modify this so that only y-values from -1 to 4 are (still) shown, but instead of 0.05*e^x there is e^x shown?

I know that this is quite impossible if function oscillates. But let's suppose that we are plotting function with one local minimun or no minimun at all.

## Best Answer

Is this what you seek? clip technique is used to cut the curve exceeds the window generated by clip. Please note that when

`clip`

is used, the clipping effect should be limited within the`scope`

. Without`scope`

the clipping will continue to take effect all the way down in the code.Update:A draw based on`PGFPLOTS`

is added for reference.Code