所以 ...

所以 ...

我有一条y = (3/2)*x + 1/2要在域 上绘制的线[-23/9,9]。绘制的线的端点应该是(-23/9,-10/3)(9,14)。该线不是沿着其域绘制的。我已将线的标签正确放置在 处(9,14),但线的右箭头不在那里。

\documentclass{amsart}
\usepackage{mathtools,array}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}

\begin{tikzpicture}
\begin{axis}[width=4.5in, axis equal image, clip=false,
    axis lines=middle,
    xmin=-6,xmax=9,
    ymin=-2.5556,ymax=14,
    restrict y to domain=-2.5556:14,
    xtick={\empty},ytick={\empty},
    axis line style={latex-latex},
    xlabel=\textit{x}, ylabel=\textit{y},
    axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
    xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
    ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west}
]

\addplot[latex-latex, domain=-6:9] {(-2/3)*x + 8/3};
\addplot[latex-latex, domain=-23/9:9] {(3/2)*x + 1/2};

\addplot [dashed, latex-latex,domain=-2.5556:14] (6,x);
\addplot [dashed, domain=1:6] {2};

\coordinate (A) at (1,2);
\coordinate (B) at (6,19/2);
\coordinate (C) at (6,-4/3);
\coordinate (P) at (6,2);


\coordinate (label_for_k) at (9,-10/3);
\coordinate (label_for_ell) at (9,14);


\draw[fill=green] (label_for_ell) circle (1.5pt);

\end{axis}


\node[anchor={atan(-2/3)+180}, inner sep=0, font=\footnotesize] at ($(label_for_k) +({atan(-2/3)}:0.15)$){\textit{k}};
\node[anchor={atan(3/2)+180}, inner sep=0, font=\footnotesize] at ($(label_for_ell) +({atan(3/2)}:0.15)$){$\ell$};


%A "pin" is drawn between the label for A and the point itself.
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (A) -- ($(A) +({0.5*(atan(-2/3)+atan(3/2))+180}:1)$);
\node[anchor=north west, inner sep=0, outer sep=0, font=\scriptsize] at ($(A) +({0.5*(atan(-2/3)+atan(3/2))+180}:1)$){\makebox[0pt][r]{\textit{A}}};

%A "pin" is drawn between the label for B and the point itself.
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (B) -- ($(B) +({0.5*(atan(3/2)-90)}:0.75)$);
\node[anchor=north west, inner sep=0, outer sep=0, font=\scriptsize] at ($(B) +({0.5*(atan(3/2)-90)}:0.75)$){\makebox[0pt][l]{\textit{B}}};

%A "pin" is drawn between the label for C and the point itself.
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (C) -- ($(C) +({0.5*(atan(-2/3)+90)+180}:0.75)$);
\node[anchor=north east, inner sep=0, outer sep=0, font=\scriptsize] at ($(C) +({0.5*(atan(-2/3)+90)+180}:0.75)$){\makebox[0pt][r]{\textit{C}}};


%A right-angle mark is drawn at A.
\coordinate (U) at ($(A)!3.5mm!-45:(B)$);
\draw ($(A)!(U)!(B)$) -- (U) -- ($(A)!(U)!(C)$);


%A right-angle mark is drawn at P.
\coordinate (V) at ($(P)!3.5mm!-45:(C)$);
\draw ($(A)!(V)!(P)$) -- (V) -- ($(B)!(V)!(P)$);



\end{tikzpicture}

\end{document}

答案1

简短回答:删除您的restrict y to domain=-2.5556:14设置。


旁注:您是想让ymin=-3.333restrict y to domain=-3.333:14吗?对于 x=-23/9,函数值如您所说是 10/3,而不是 -23/9。


删除大部分代码后,剩下下面的示例演示了该问题,其中刻度和网格仅用于使其易于查看:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xmin=-6,xmax=9,
    ymin=-2.5556,ymax=14,
    xtick={-2.5556,9},
    ytick={-2.5556,14},
    grid,
    restrict y to domain=-2.5556:14
]

  \addplot +[domain=-23/9:9] {(3/2)*x + 1/2};
\end{axis}
\end{tikzpicture}
\end{document}

该图应该延伸到右上角和左下角,但事实并非如此:

在此处输入图片描述

如果您继续从中删除选项axis,您会发现这是restrict y to domain导致问题的关键。结合pgfplots默认情况下使用 25 个样本的事实(我相信我之前已经讨论过您的一些问题),情节线在远离右上角的地方结束。

我意识到理论上应该包括 x=9 的数据点,但显然计算和比较会将pgfplots其过滤掉。这可能与未使用 pgfplots 绘制的线

restrict y to domain这是一个包含特定内容(带有蓝色标记)的示例\addplot,而不是选项axis

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines=middle,
    xmin=-6,xmax=9,
    ymin=-3.333,ymax=14,
    clip=false,
    only marks,
    xtick={-2.5556,9},
    ytick={-3.333,14},
    grid
]

\addplot[red, domain=-23/9:9, mark=o] {(3/2)*x + 1/2};
\addplot[blue, restrict y to domain=-2.5556:14,domain=-23/9:9, mark=*] {(3/2)*x + 1/2};

\end{axis}
\end{tikzpicture}

\end{document}

所以 ...

回到你原来的代码,我想我可能会使用samples at而不是domain。但它似乎不允许分数,所以如果你希望使用 -23/9 而不是 -2.5556,请使用例如domain=-23/9:9, samples=2而不是samples at={-2.5556, 9}

当然,您仍然需要删除该restrict y to domain线,否则您将不会得到任何图。

在此处输入图片描述

\documentclass{amsart}
\usepackage{mathtools,array}

\usepackage{pgfplots} % loads tikz
\pgfplotsset{compat=1.11}
\usetikzlibrary{calc,intersections}

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=4.5in, axis equal image, clip=false,
    axis lines=middle,
    xmin=-6,xmax=9,
    ymin=-3.333, % changed from 2.5556
    ymax=14,
    %restrict y to domain=-2.5556:14, % you don't want this
    xtick={\empty},ytick={\empty},
    axis line style={latex-latex},
    xlabel=\textit{x}, ylabel=\textit{y},
    axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
    xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
    ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west}
]

% used samples=at in the following four \addplots
\addplot[latex-latex, samples at={-6,9}] {(-2/3)*x + 8/3};
\addplot[latex-latex, samples at={-2.5556,9}] {(3/2)*x + 1/2};

\addplot [dashed, latex-latex,samples at={-2.5556,14}] (6,x);
\addplot [dashed, samples at={1,6}] {2};

\coordinate (A) at (1,2);
\coordinate (B) at (6,19/2);
\coordinate (C) at (6,-4/3);
\coordinate (P) at (6,2);


\coordinate (label_for_k) at (9,-10/3);
\coordinate (label_for_ell) at (9,14);


\draw[fill=green] (label_for_ell) circle (1.5pt);

\end{axis}


\node[anchor={atan(-2/3)+180}, inner sep=0, font=\footnotesize] at ($(label_for_k) +({atan(-2/3)}:0.15)$){\textit{k}};
\node[anchor={atan(3/2)+180}, inner sep=0, font=\footnotesize] at ($(label_for_ell) +({atan(3/2)}:0.15)$){$\ell$};


%A "pin" is drawn between the label for A and the point itself.
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (A) -- ($(A) +({0.5*(atan(-2/3)+atan(3/2))+180}:1)$);
\node[anchor=north west, inner sep=0, outer sep=0, font=\scriptsize] at ($(A) +({0.5*(atan(-2/3)+atan(3/2))+180}:1)$){\makebox[0pt][r]{\textit{A}}};

%A "pin" is drawn between the label for B and the point itself.
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (B) -- ($(B) +({0.5*(atan(3/2)-90)}:0.75)$);
\node[anchor=north west, inner sep=0, outer sep=0, font=\scriptsize] at ($(B) +({0.5*(atan(3/2)-90)}:0.75)$){\makebox[0pt][l]{\textit{B}}};

%A "pin" is drawn between the label for C and the point itself.
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (C) -- ($(C) +({0.5*(atan(-2/3)+90)+180}:0.75)$);
\node[anchor=north east, inner sep=0, outer sep=0, font=\scriptsize] at ($(C) +({0.5*(atan(-2/3)+90)+180}:0.75)$){\makebox[0pt][r]{\textit{C}}};


%A right-angle mark is drawn at A.
\coordinate (U) at ($(A)!3.5mm!-45:(B)$);
\draw ($(A)!(U)!(B)$) -- (U) -- ($(A)!(U)!(C)$);


%A right-angle mark is drawn at P.
\coordinate (V) at ($(P)!3.5mm!-45:(C)$);
\draw ($(A)!(V)!(P)$) -- (V) -- ($(B)!(V)!(P)$);


\end{tikzpicture}

\end{document}

相关内容