这里,我尝试TikZ
绘制直线 y=x。出现错误。
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{mathtools,systeme,array}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,clip=false,
axis lines=middle,
xmin=-7,xmax=17,
xlabel=$x$,ylabel=$y$,
ymin=-4,ymax=14,
restrict y to domain=-4:14,
enlargelimits={abs=0.25cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={\empty},ytick={\empty},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[dashed,samples=2,domain=-6:16]{x};
\end{tikzpicture}
\end{document}
答案1
你缺少了\end{axis}
。一旦你添加,你的MWE就会编译并生成:
samples=2
由于您已设置和,domain=-6:16
但也有,因此不会显示任何点restrict y to domain=-4:14
。因此,两个样本点x=-6
和x=16
未绘制,因为它们超出了您对的限制y
。
最好的解决方案是消除samples=2
或指定更大数量的samples=
:
代码:
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{mathtools,systeme,array}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=4in, axis equal image, clip=false,
axis lines=middle,
xmin=-7, xmax=17,
xlabel=$x$, ylabel=$y$,
ymin=-4, ymax=14,
restrict y to domain=-4:14,
enlargelimits={abs=0.25cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={\empty}, ytick={\empty},
xlabel style={at={(ticklabel* cs:1)}, anchor=north west},
ylabel style={at={(ticklabel* cs:1)}, anchor=south west}
]
\addplot[dashed,domain=-6:16, ultra thick, blue] {x};
\end{axis}% <---- Was missing
\end{tikzpicture}
\end{document}