MWE(钛钾Z)

MWE(钛钾Z)

我正在尝试绘制一条通过端点为 $P = (1,-1)$ 和 $Q = (3,-6)$ 的线段的垂直平分线。(定义域是范围长度的两倍。)

\documentclass{amsart}
\usepackage{tikz}

\usetikzlibrary{calc,intersections}

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


\begin{document}

\begin{tikzpicture}
\begin{axis}[width=3.25in, height=3.25in, clip=false,
    axis lines=middle,
    xmin=-5,xmax=15,
    ymin=-7,ymax=3,
    restrict y to domain=-7:3,
    axis line style={latex-latex},
    xlabel=$x$,ylabel=$y$,
    xtick={\empty},ytick={\empty},
    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}
]


%The equation for the line through P and Q is (-5/2)*x + 3/2, and the equation for line $\ell$
%that is the perpendicular bisector for PQ is y = (2/5)x - 43/10.  The x-intercept for $\ell$
%is (43/4, 0).

\addplot[latex-latex, dashed, domain=-17/4:15] {(2/5)*x - 43/10};
\addplot[domain=1:3] {(-5/2)*x + 3/2};

\draw[fill] (1,-1) circle [radius=1.5pt];
\draw[fill] (3,-6) circle [radius=1.5pt];

\coordinate (label_for_ell) at (15,17/10);

\coordinate (label_for_P) at (1,-1);
\coordinate (label_for_Q) at (3,-6);

\end{axis}

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

\draw node[anchor={atan(-5/2)-90}, inner sep=0, font=\footnotesize] at ($(label_for_P) +({atan(-5/2)+90}:0.15)$){$P$};
\draw node[anchor={atan(-5/2)-90}, inner sep=0, font=\footnotesize] at ($(label_for_Q) +({atan(-5/2)+90}:0.15)$){$Q$};

\end{tikzpicture}

\end{document}

答案1

John 的意思是,在使用 PGFplots 时,会进行大量的缩放,因此 PGFplots 提供了几个额外的坐标系。有一个axis cs表示轴值的,假设您正在处理对数图,那么(axis cs:10000,100)实际上不是(10000cm,100cm),如果省略了,则使用和键的axis cs:默认值。xy

还有axis description cs对应于轴框并以 0 到 1 的尺度给出的坐标。举例来说,(axis description cs:0,0)轴框的左下角和(axis description cs:1,1)右上角。甚至还有其他有用的坐标系,所有这些信息都可以更详细地获得在 PGFplots 手册中

所以这就是为什么axis你通常不想使用自然坐标系,因为它有缩放比例的问题。

不过,在我看来,就目前的情节/绘图而言,PGFplots 有点过度了。TiZ 可以轻松处理,所以下面有一个纯 TiZ MWE 和您的 MWE 进行了适当的更改(axis equal=true并且还存在额外的内容shorten,将箭头抛出了边界框)。

MWE(钛Z)

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
    >=latex, axis/.style={<->},
    point/.style={circle, inner sep=0pt, fill, minimum size=4pt, label=#1},
    scale=.75]
\draw[axis] (0,-7) -- (0,3) node[above right]{$y$};
\draw[axis] (-5,0) -- (15,0) node[below right]{$x$};
\node[point=$P$] (P) at (1,-5/2 + 3/2) {};
\node[point=$Q$] (Q) at (3,-5*3/2 + 3/2) {};
\draw (P) -- (Q);
\draw[<->,dashed] (-17/4,{(2/5)*(-17/4) - 43/10}) -- (15,15*2/5 - 43/10) node[above]{$\ell$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

MWE(PGF 图)

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usetikzlibrary{calc,intersections}
\pgfplotsset{compat=1.11}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
        width=3.25in, height=3.25in, clip=false, axis equal=true,
        axis lines=middle,
        xmin=-5,xmax=15,
        ymin=-7,ymax=3,
        restrict y to domain=-7:3,
        axis line style={latex-latex},
        xlabel=$x$,ylabel=$y$,
        xtick={\empty},ytick={\empty},
        axis line style={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}
    ]
      %The equation for the line through P and Q is (-5/2)*x + 3/2, and the equation for line $\ell$
      %that is the perpendicular bisector for PQ is y = (2/5)x - 43/10.  The x-intercept for $\ell$
      %is (43/4, 0).

      \addplot[latex-latex, dashed, domain=-17/4:15] {(2/5)*x - 43/10};
      \addplot[domain=1:3] {(-5/2)*x + 3/2};

      \draw[fill] (axis cs:1,-1) circle [radius=1.5pt];
      \draw[fill] (axis cs:3,-6) circle [radius=1.5pt];

      \coordinate (label_for_ell) at (axis cs:15,17/10);

      \coordinate (label_for_P) at (axis cs:1,-1);
      \coordinate (label_for_Q) at (axis cs:3,-6);
    \end{axis}

    \draw node[anchor={atan(2/5)+180}, inner sep=0, font=\footnotesize] at ($(label_for_ell) +({atan(2/5)}:0.15)$){$\ell$};
    \draw node[anchor={atan(-5/2)-90}, inner sep=0, font=\footnotesize] at ($(label_for_P) +({atan(-5/2)+90}:0.15)$){$P$};
    \draw node[anchor={atan(-5/2)-90}, inner sep=0, font=\footnotesize] at ($(label_for_Q) +({atan(-5/2)+90}:0.15)$){$Q$};
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容