编译 GeoGebra 生成的 PGF/TikZ 时出错

编译 GeoGebra 生成的 PGF/TikZ 时出错

我尝试使用 GeoGebra 生成正态分布图,然后将其导出到 PGF/TikZ。我得到了以下 LaTex 代码。但是当我将它们粘贴到 TexStudio 中并进行编译时,我收到了错误消息line 19: Dimension too large \end{frame}。我该怎么办?谢谢!

在此处输入图片描述

\documentclass[10pt]{beamer}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\begin{frame}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=black] (-4,0) -- (4,0);
\foreach \x in {-4,-3,-2,-1,1,2,3}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt);
\draw[->,color=black] (0,-0.01) -- (0,0.46);
\foreach \y in {,0.2,0.3,0.4}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt);
\clip(-4,-0.01) rectangle (4,0.46);
\onslide<2->{
  \draw[smooth,samples=100,domain=-4.0:4.0] plot(\x,{2.718281828^((-((\x))^2)/(1^2*2))/(abs(1)*sqrt(3.1415926535*2))});
}
\end{tikzpicture}
\end{frame}
\end{document}

答案1

主要错误来自指数运算符的 2.718281828^,而指数运算符应该是exp()。第二个错误是clip命令应该限制在scope环境中。由于正态分布非常小,因此yscale=4在示波器中使用 来放大以获得更好的视图。

在此处输入图片描述

\documentclass[10pt]{beamer}
\usepackage{pgf,tikz}

\usetikzlibrary{arrows}
\pagestyle{empty}


\begin{document}
\begin{frame}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45]
\begin{scope}[yscale=4]
\draw[->,color=black] (-4,0) -- (4,0);
\foreach \x in {-4,-3,-2,-1,1,2,3}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt);
\draw[->,color=black] (0,-0.01) -- (0,0.46);
\foreach \y in {0,0.1,0.2,0.3,0.4}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt);
\clip(-4,-0.01) rectangle (4,0.46);
\onslide<2>{
%\draw[smooth,samples=100,domain=-4.0:4.0] plot(\x,{2.718281828^((-((\x))^2)/(1^2*2))/(abs(1)*sqrt(3.1415926535*2))});  <---- error in this line
\draw[smooth,samples=100,domain=-4.0:4.0]
plot(\x,{exp((-((\x))^2)/(1^2*2))/(abs(1)*sqrt(3.1415926535*2))});
%\draw[smooth,samples=100,domain=-4.0:4.0] plot(\x,{exp((-(\x)^2)/(2*1^2))/(abs(1)*sqrt(pi*2))});  <---- change 3.1415.... int0 pi
}
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}

相关内容