忽略轴环境中的规范

忽略轴环境中的规范

这是我另一篇文章中的类似显示。只有两个不同之处。(其中一个不同之处是线条标签的位置。在我的文章中,我将标签放在线条上。由于 Gonzalo Medina 的评论,我现在将标签放在线条末尾。)另一个不同之处是我编辑了环境axis以使其更简洁。我添加了

x tick label style={font=\tiny,fill=white,anchor=south,shift=-4pt}

xticklabel style=

y tick label style={font=\tiny,fill=white,anchor=west,shift=-4pt}

yticklabel style=。为什么这些规范被忽略了?

\documentclass{amsart}
\usepackage{amsmath}

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


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


\begin{document}

\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,clip=false,
    xmin=-54,xmax=90,ymin=-54,ymax=90,
    restrict y to domain=-54:90,
    enlargelimits={abs=0.5cm},
    xtick={\empty},ytick={\empty},
    extra x ticks={15},
    extra x tick labels={15},
    xticklabel style={x tick label style={font=\tiny,fill=white,anchor=south,shift=-4pt}},
    extra y ticks={15},
    extra y tick labels={15},
    yticklabel style={y tick label style={font=\tiny,fill=white,anchor=west,shift=-4pt}},
    axis lines=middle,
    axis line style={latex-latex},
    xlabel=$x$,ylabel=$y$,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
    ]

%These commands draw the line y=x and put the label "$\ell$" 7.5pt from the right arrow tip
%in the same direction of the line.
\addplot[dashed,latex-,samples=2,domain=-54:-21,blue]{(1/3) * x + 36};
\addplot[dashed,-latex,samples=2,domain=18:90,blue]{(1/3) * x + 36};
\addplot[dashed,latex-latex,samples=2,domain=-54:90]{x};
\node at ($(axis cs:90,90)!7.5pt!(axis cs:100,100)$) {$\ell$};

%These commands label the vertices of triangle ABC. P is the point on line segment AC at the
%base of the altitude from B.
\draw (axis cs:-30,-30) coordinate(A) node[left]{$A$};
\draw (axis cs:-21,29) coordinate(B) node[above left]{$B$};
\draw (axis cs:18,42) coordinate(C) node[above]{$C$};
\draw (axis cs:0,15) coordinate(P);

%These commands draw a line through B and C.
\addplot[dashed,latex-,samples=2,domain=-54:90,blue]{(1/3) * x + 36};

%These commands label the vertices of triangle AB'C'. (The reflection of B across the line
%y=x is labeled B' and the reflection of C across the line y=x is labeled C'.) P' is the
%point on line segment AC' at the base of the altitude from B'.
\draw (axis cs:29,-21) coordinate(B') node[below right]{$B^{\prime}$};
\draw (axis cs:42,18) coordinate(C') node[right]{$C^{\prime}$};
\draw (axis cs:15,0) coordinate(P');

%These commands draw a line through B' and C'. (Its domain is expressed as the union of the
%intervals [18,29] and [42,66] because the side B'C' is dashed and the line through B' and
%C' is drawn with "loosely dash dot.")
\addplot[latex-,samples=2,loosely dash dot,domain=18:29,green]{3 * x - 108};
\addplot[-latex,samples=2,loosely dash dot,domain=42:66,green]{3 * x - 108};

\draw [fill] (54,54) circle [radius=1.5pt];
\end{axis}

\draw[blue] (A) -- (B) -- (C) -- cycle;
\draw[dashed,blue] (B) -- (P);


\draw[dashed,green] (A) -- (B') -- (C') -- cycle;
\draw[densely dashed,green] (B') -- (P');

\end{tikzpicture}

\end{document}

答案1

您正在嵌套相同样式的键:出于兼容性原因,xticklabel stylex tick label style是同一键的缩写every x tick label/.style。删除内部或外部即可产生效果。

编辑:为了澄清评论中的讨论,我添加了完整的 MWe 并进行了一些解释:

\documentclass{amsart}
    \usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{calc,angles,positioning,intersections}
% just to show only picture
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
    \setlength\PreviewBorder{1em}

    \begin{document}
\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,clip=false,
    xmin=-54,xmax=90,ymin=-54,ymax=90,
    restrict y to domain=-54:90,
    enlargelimits={abs=0.5cm},
    xtick={\empty},ytick={\empty},
    extra x ticks={15},
    extra x tick labels={15},
% here is correct definition of xticklabel, 
% also are corrected anchor and deleted shift, it is now unnecessary
    xticklabel style={font=\tiny,fill=white,anchor=north},
    extra y ticks={15},
    extra y tick labels={15},% here is correct definition of xticklabel, 
% here is correct definition of yticklabel, 
    yticklabel style={font=\tiny,fill=white,anchor=west,xshift=+4pt},
    axis lines=middle,
    axis line style={latex-latex},
    xlabel=$x$,ylabel=$y$,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
    ]
\addplot[dashed,latex-,samples=2,domain=-54:-21,blue]{(1/3) * x + 36};
\addplot[dashed,-latex,samples=2,domain=18:90,blue]{(1/3) * x + 36};
\addplot[dashed,latex-latex,samples=2,domain=-54:90]{x};
\node at ($(axis cs:90,90)!7.5pt!(axis cs:100,100)$) {$\ell$};

\draw (axis cs:-30,-30) coordinate(A) node[left]{$A$};
\draw (axis cs:-21,29) coordinate(B) node[above left]{$B$};
\draw (axis cs:18,42) coordinate(C) node[above]{$C$};
\draw (axis cs:0,15) coordinate(P);

\addplot[dashed,latex-,samples=2,domain=-54:90,blue]{(1/3) * x + 36};

\draw (axis cs:29,-21) coordinate(B') node[below right]{$B^{\prime}$};
\draw (axis cs:42,18) coordinate(C') node[right]{$C^{\prime}$};
\draw (axis cs:15,0) coordinate(P');

\addplot[latex-,samples=2,loosely dash dot,domain=18:29,green]{3 * x - 108};
\addplot[-latex,samples=2,loosely dash dot,domain=42:66,green]{3 * x - 108};

\draw [fill] (54,54) circle [radius=1.5pt];
\end{axis}

\draw[blue] (A) -- (B) -- (C) -- cycle;
\draw[dashed,blue] (B) -- (P);

\draw[dashed,green] (A) -- (B') -- (C') -- cycle;
\draw[densely dashed,green] (B') -- (P');
\end{tikzpicture}
    \end{document}

在此处输入图片描述

关于shift:您可以声明某个物体的偏移量为shift=(x-direction,y-direction)或 仅在 x 方向为xshif=<x-distance>或 y 方向为yshift=<y-distance。在您的例子中,不是shift=-4pt for shifting in x direction should bexshif=-4pt or if you persist to use just shift: ˙shift=(-4pt,0pt)`。

相关内容