答案1
选项 1:限制域
缺点:您必须考虑合理的截止点在哪里。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->] (-3,0) -- (3,0) node[right] {$x$};
\draw[->] (0,-3) -- (0,3) node[above] {$y$};
\draw[domain=-3:1, variable=\x, red] plot ({\x}, {exp(\x)}) node[right] {$e^x$};
\end{tikzpicture}
\end{document}
选项 2:剪辑
缺点:剪切区域之外的东西(这里是标签)就会消失。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->] (-3,0) -- (3,0) node[right] {$x$};
\draw[->] (0,-3) -- (0,3) node[above] {$y$};
\clip (-3,-3) rectangle (3,3);
\draw[domain=-3:3, variable=\x, red] plot ({\x}, {exp(\x)}) node[right] {$e^x$};
\end{tikzpicture}
\end{document}
选项 3:使用pgfplots
缺点:相当冗长。
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
domain=-3:3,
xmin=-3, xmax=3,
ymin=-3, ymax=3,
xlabel={$x$},
ylabel={$y$},
restrict y to domain=-3:3,
]
\addplot+[no marks] {exp(x)} node[right] {$e^x$};
\end{axis}
\end{tikzpicture}
\end{document}