我有下面这段代码,尽管我可以使用 pgfplots 来实现相同的目标,但由于遗留原因,大多数 tikz 代码都是这样的。
\begin{tikzpicture}
\pgfkeys{/pgf/fpu=true,
/pgf/fpu/output format=fixed
}
% low pass
\draw[->] (0,0) -- (0,2) node[left] {$V$};
\draw[->] (-0.5,0) -- (4,0) node[below] {$f$};
\draw[line width=1pt, domain=0:4, smooth,
blue,samples=1000] plot ({\x},{1/(1+(\x/2)^24)}); \draw
(3,1.5) node[] {lowpass};
\end{tikzpicture}
上面的编译出现以下错误:
! Package PGF Math Error: Sorry, an internal routine of the floating point unit
got an ill-formatted floating point number `-56.90549000000000'. The unreadabl
e part was near '-56.90549000000000'..
使用了以下包和库:
\usepackage{graphicx,tikz,pgfplots,float}
\usetikzlibrary{arrows,shapes,er,intersections,decorations,positioning,shapes.geometric,matrix,decorations.pathreplacing,calc}
错误原因是什么?
答案1
该密钥/pgf/fpu=true
破坏了大部分 TikZ 绘图代码,因为解析和格式化之间没有分离,另请参阅https://github.com/pgf-tikz/pgf/issues/678。
但是,您始终可以尝试在本地使用/pgf/fpu=true
导致问题的单一路径,Dimension too large
并祈祷它不会破坏其他任何东西。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fpu}
\begin{document}
\begin{tikzpicture}
% low pass
\draw[->] (0,0) -- (0,2) node[left] {$V$};
\draw[->] (-0.5,0) -- (4,0) node[below] {$f$};
\draw[line width=1pt,domain=0:4,smooth,blue,samples=1000,/pgf/fpu=true,/pgf/fpu/output format=fixed] plot ({\x},{1/(1+(\x/2)^24)});
\draw (3,1.5) node[] {lowpass};
\end{tikzpicture}
\end{document}
$ bench "pdflatex test.tex"
benchmarking pdflatex test.tex
time 1.387 s (1.226 s .. 1.550 s)
0.998 R² (0.993 R² .. 1.000 R²)
mean 1.310 s (1.252 s .. 1.356 s)
std dev 58.24 ms (26.01 ms .. 76.84 ms)
variance introduced by outliers: 19% (moderately inflated)
但是如果你只想绘制曲线的示意图,我建议你使用贝塞尔曲线来获得平滑的拐角。这看起来几乎完全相同,但不会使文档的编译时间激增。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% low pass
\draw[->] (0,0) -- (0,2) node[left] {$V$};
\draw[->] (-0.5,0) -- (4,0) node[below] {$f$};
\draw[line width=1pt,blue] (0,1) -- (1.5,1) .. controls (2.2,1) and (1.8,0) .. (2.5,0) -- (4,0);
\draw (3,1.5) node[] {lowpass};
\end{tikzpicture}
\end{document}
$ bench "pdflatex test.tex"
benchmarking pdflatex test.tex
time 292.8 ms (277.8 ms .. 302.3 ms)
0.999 R² (NaN R² .. 1.000 R²)
mean 298.0 ms (292.9 ms .. 300.7 ms)
std dev 4.747 ms (1.946 ms .. 6.257 ms)
variance introduced by outliers: 16% (moderately inflated)