我在评估 TikZ 图片中的表达式时经常遇到问题sqrt(\x)
。2^{\x^2}
以下是一个例子:
{
\begin{tikzpicture}[scale=2]
\draw[draw=gray!50!white,fill=gray!50!white]
plot[smooth,samples=100,domain=0:1] (\x*\x,1+\x) --
plot[smooth,samples=100,domain=0:1] (\x,2^{\x^2});
\draw[domain=0:1] plot (\x*\x,1+\x);
\draw[samples=100,domain=0:1] plot (\x,2^{\x^2});
\draw (-.5,0)--(1.25,0) node[right]{$x$};
\draw (0,-.5)--(0,2.25) node[above]{$y$};
\draw (1,2pt)--(1,-2pt) node[below] {$1$};
\foreach \y/\ytext in {1,2}
\draw (2pt,\y)--(-2pt,\y) node[left] {$\y$};
\end{tikzpicture}
}
我设法避免使用sqrt(\x)
,但无法使其他功能正常工作。我做错了什么?
答案1
您需要进行一些更正。为了让 tiKZ 正确解析函数表达式,它需要在其周围加上两个大括号。因此,其余表达式也(\x*\x,1+\x)
应如此。此外,为什么要避免或类似?TikZ 可以轻松处理这些函数,例如。({\x*\x},{1+\x})
sqrt(\x)
\pgfmathsqrt{x} \pgfmathresult
\documentclass[tikz,border=2pt]{standalone}
\begin{document}
\begin{tikzpicture}[scale=2]
\draw[draw=gray!50!white,fill=gray!50!white]
plot[smooth,samples=100,domain=0:1] ({\x*\x},{1+\x}) --
plot[smooth,samples=100,domain=0:1] ({\x},{2^(\x^2)});
\draw[domain=0:1] plot (\x*\x,1+\x);
\draw[samples=100,domain=0:1] plot ({\x},{2^(\x^2)});
\draw (-.5,0)--(1.25,0) node[right]{$x$};
\draw (0,-.5)--(0,2.25) node[above]{$y$};
\draw (1,2pt)--(1,-2pt) node[below] {$1$};
\foreach \y/\ytext in {1,2}
\draw (2pt,\y)--(-2pt,\y) node[left] {$\y$};
\end{tikzpicture}
\end{document}