代码末尾有一个错误,它说“缺少数字,视为零”,我不知道那是什么意思。我如何在这段代码中找到它?
\begin{axis}[
x=1.3333333333333333cm,y=1.1627906976744187cm,
axis lines=middle,
xlabel=$x$,
ylabel=$y$,
xmin=-2.0,
xmax=4.0,
ymin=-2.0,
ymax=2.3,
xtick={\empty},
ytick={\empty},]
\clip(-2.,-2.) rectangle (4.,2.3);
\draw[line width=1.2pt,smooth,samples=100,domain=-2.0:4.0] plot(\x,{(\x)^(2)-1});
\draw[line width=1.2pt,smooth,samples=100,domain=4.0000000012539686E-6:4.0] plot(\x,{ln((\x))});
\draw (1.8855684490090832,2.1448633485685624) node[anchor=north west] {$y = g(x)$};
\draw (2.3,1) node[anchor=north west] {$y = f(x)$};
\end{axis}
\end{tikzpicture}
答案1
你的代码很乱pgfplots
,而且tikz
画图的方式也多种多样。请只坚持一种。我会选择pgfplots
。此时我会考虑建议在@Werner 评论中给出的链接中:
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[
lbl/.style = {font=\footnotesize, text=black, inner sep=2pt, anchor=north west, pos=#1}
]
\begin{axis}[
axis lines=middle,
enlargelimits=0.1, % added
xlabel=$x$,
ylabel=$y$,
label style = {anchor=north east},
ymin=-2.0,
xtick={\empty},
ytick={\empty},
samples=100, no marks,
every axis plot post/.append style={very thick}
]
\addplot +[domain=-2:2] {(x)^2-1} node[lbl=1] {$y = g(x)$};
\addplot +[domain= 0:4] {ln(x)} node[lbl=0.85] {$y = f(x)$};
\end{axis}
\end{tikzpicture}
\end{document}
与上述代码片段相比,建议的解决方案仅使用pgfplots
语法来绘制曲线。除此之外,还进行了一些小改动,为曲线添加了标签。还请注意定义域的变化。