未绘制的线

未绘制的线

这里,我尝试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=-6x=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}

相关内容