向 tikz 绘图添加函数

向 tikz 绘图添加函数

我想知道是否有一种方法可以向 tikz 绘图添加函数,而无需使用 axis 环境中的 pgfplots 包。我希望在此图像中沿虚线添加正弦函数:

\begin{center}
\begin{tikzpicture}[scale=0.5]
\draw (0,4) -- (2,4);
\draw (8,4) -- (10,4);
\draw[line width=3, color=blue] (2,0) -- (8,0);
\draw (2,0) -- (2,-0.5);
\draw (8,0) -- (8,-0.5);
\draw[line width=3, color=blue] (2,-0.1) -- (2,4);
\draw[line width=3, color=blue] (8,-0.1) -- (8,4);
\draw[dashed] (1.5,2) -- (9,2);
\node [left] at (1.5,2) {$E<U_o$};
\node [below] at (2,-0.5) {$0$};
\node [below] at (8,-0.5) {$a$};
\node [left] at (0,4) {$U_o$};
\end{tikzpicture}
\end{center}

如果可能的话,我还想添加其他函数,例如指数函数。谢谢。

答案1

我认为你没有看太多,无论是在文档中还是在互联网上(如何使用 TikZ 绘制类似 ‎‎‎‎‎x=f(y)‎‎ 的函数?tikz)这里有一个答案,你将调节振幅和脉动。

\documentclass{article}
\usepackage{tikz}
%\usetikzlibrary{calc,matrix,positioning}

\begin{document}
\begin{center}
\begin{tikzpicture}[scale=0.5]
\draw (0,4) -- (2,4);
\draw (8,4) -- (10,4);
\draw[line width=3, color=blue] (2,0) -- (8,0);
\draw (2,0) -- (2,-0.5);
\draw (8,0) -- (8,-0.5);
\draw[line width=3, color=blue] (2,-0.1) -- (2,4);
\draw[line width=3, color=blue] (8,-0.1) -- (8,4);
\draw[dashed] (1.5,2) -- (9,2);
\node [left] at (1.5,2) {$E<U_o$};
\node [below] at (2,-0.5) {$0$};
\node [below] at (8,-0.5) {$a$};
\node [left] at (0,4) {$U_o$};
\draw[domain=-1:10, smooth, variable=\x, blue] plot ({\x}, {2*sin(30*\x)+1.5});
\end{tikzpicture}
\end{center}

\end{document}

在此处输入图片描述

相关内容