我在使用 Tikz 绘制此图表时遇到困难。我收到“Dimension Too Large”错误。我通过 Geogebra 生成的代码是:
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=black] (-4.3,0.0) -- (7.3,0.0);
\foreach \x in {-4.0,-3.0,-2.0,-1.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0.0,-3.12) -- (0.0,6.3);
\foreach \y in {-3.0,-2.0,-1.0,1.0,2.0,3.0,4.0,5.0,6.0}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-4.3,-3.12) rectangle (7.3,6.3);
\draw[smooth,samples=100,domain=-4.3:7.3] plot(\x,{0.7*2.718281828^(-(\x)^(2.0))});
\begin{scriptsize}
\draw[color=black] (-4.140000000000001,-0.12000000000000002) node {$f$};
\end{scriptsize}
\end{tikzpicture}
有人知道这是为什么吗?这似乎是指数特有的问题,因为我已经尝试了不同的函数并且它运行良好。
答案1
运行xelatex
:
\documentclass[pstricks,border=10pt]{standalone}
\usepackage{pst-plot}
\begin{document}
%\psset{yunit=10}
\begin{pspicture}(-4.4,-0.4)(4.4,7.4)
\psaxes{->}(0,0)(-4,0)(4,7)
\psplot[plotpoints=1000,algebraic,yMaxValue=6,linecolor=red,linewidth=1.5pt]{-4}{4}{0.6*Euler^((-x)^2)}
\psplot[plotpoints=1000,algebraic,linecolor=blue,linewidth=1.5pt]{-4}{4}{6*Euler^(-x^2)}
\end{pspicture}
\end{document}
答案2
我假设它是e^{-(x^2)}
您想要绘制的函数。否则 Jesse 似乎已经回答了这个问题。为了好玩,下面是使用 MetaPost 和 LuaLaTeX 的尝试:
\documentclass{standalone}
\usepackage{luamplib}
\mplibsetformat{metafun}
\mplibnumbersystem{double}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
% The Gaussian function
vardef f(expr x) = 0.7exp(-(x**2)) enddef;
% Macro for drawing a function curve
vardef graph_of_function (suffix f) (expr xmin, xmax, xstep) =
for x = xmin step xstep until xmax: (x, f(x)) .. endfor (xmax, f(xmax))
enddef ;
% Parameters
u = 1cm;
xmin = -7; xmax = -xmin; ymin = -.5; ymax = 1.75; xstep = .1;
Xmin = -7.5; Xmax = -Xmin;
beginfig(1);
% Axes
drawarrow (Xmin*u, 0) -- (Xmax*u, 0); drawarrow (0, ymin*u) -- (0, ymax*u);
% Curve
draw graph_of_function(f, xmin, xmax, xstep) scaled u withcolor red;
% Marking
labeloffset := 5bp;
for i = -floor(-xmin) upto floor(xmax) :
if i <> 0:
draw (i*u, -2bp) -- (i*u, 2bp);
label.bot("$" & decimal(i) & "$", (i*u, 0));
fi;
endfor;
draw (-2bp, u) -- (2bp, u);
% Labels
labeloffset := 3bp;
label.llft("$O$", origin); label.bot("$x$", (Xmax*u, 0)); label.lft("$y$", (0, ymax*u));
label.ulft("$1$", (0, u));
%
setbounds currentpicture to boundingbox currentpicture enlarged 2bp;
endfig;
\end{mplibcode}
\end{document}
答案3
和pgfplots
:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[draw = blue,domain=-10:10,samples=500] {exp(-x^2)};
\end{axis}
\end{tikzpicture}
\end{document}