在 pgfplots 中使用“anchor=north west”适当地放置轴的标签

在 pgfplots 中使用“anchor=north west”适当地放置轴的标签

我有用于轴的标签x和。我使用用于定位和用于定位。我还使用用于延伸轴。显然和不遵循此延伸。ypgfplotanchor=north westxanchor=south westyaxis line style={shorten >=-12.5pt, shorten <=-12.5pt}xy

\documentclass[10pt]{amsart}

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

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


\usepackage{mathtools,array}


\begin{document}


\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[name=axis_1, width=2.75in, height=2.75in, clip=false,
    axis lines=middle,
    xmin=-2.5,xmax=2.5,
    ymin=-15.625,ymax=15.625,
    restrict y to domain=-15.625:15.625,
    xtick={\empty}, ytick={\empty},
    xlabel=$x$,ylabel=$y$,
    axis line style={latex-latex},
    axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[samples=251, domain=-2.5:2.5] {x^3)} node[right, pos=1, font=\footnotesize]{$y = x^{3}$};

\end{axis}

%Title for the plot of the cubing function illustrating a function with no absolute extrema is typeset.
\node[font=\bfseries, anchor=north, inner sep=0, align=center] at ($(axis_1.south) +(0,-0.5)$)
{\mbox{An illustration of a function with} \\
\mbox{no extrema}};
\end{tikzpicture}
%
\qquad
%
\begin{tikzpicture}
\begin{axis}[name=axis_2, width=2.75in, height=2.75in, axis on top,
    axis lines=middle,
    xmin=-7,xmax=7, domain=-7:7,
    ymin=-1,ymax=1,
    restrict y to domain=-1:1,
    xtick={\empty},
    ticklabel style={font=\tiny},
    ytick={-1,1},
    yticklabels={$-1$, 1},
    xlabel=$x$,ylabel=$y$,
    axis line style={latex-latex},
    axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501, domain=-6.28318:6.28318] {sin(deg(x))} node[anchor=south west, pos=0.6875,font=\footnotesize]{$y = \sin{x}$};

\end{axis}

%Title for the plot of the sine function illustrating a function with absolute extrema is typeset.
\node[font=\bfseries, anchor=north, inner sep=0, align=center] at ($(axis_2.south) +(0,-0.5)$)
{\mbox{An illustration of a function with} \\
\mbox{two extrema: \boldmath$-1$ and $1$\unboldmath}};
\end{tikzpicture}

\end{document}

答案1

像这样?:

在此处输入图片描述

延长轴shorten >不会移动原始线末端的锚点(您将标签锚定到该锚点),只会进一步绘制。因此,如果您喜欢将标签锚定到延长的 exes 的末尾,则需要将标签移动与延长线相同的量。请参阅下面的 MWE。

\documentclass[10pt]{amsart}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{calc,intersections,}
\usepackage{mathtools,array}

\usepackage[showframe]{geometry}

\begin{document}
    \centering
\begin{figure}[ht]
    \pgfplotsset{width=2.75in, height=2.75in,
                 clip=false,
                 axis lines=middle,
                 axis line style={latex-latex},
                 xtick={\empty},
                 xlabel=$x$,ylabel=$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},
        title style = {at={(0.5,-0.15)},anchor=north, font=\bfseries, align=center},  
                }
    \begin{tikzpicture}
\begin{axis}[name=axis_1, 
    xmin=-2.5,xmax=2.5,
    ymin=-15.625,ymax=15.625,
    restrict y to domain=-15.625:15.625,
    ytick={\empty},
%
       title = {An illustration of a function with \\
                no extrema},
                ]

\addplot[samples=251, domain=-2.5:2.5] {x^3)} 
    node[right, font=\footnotesize]{$y = x^{3}$};
\end{axis}
    \end{tikzpicture}
%
\hfill %qquad
%
    \begin{tikzpicture}
\begin{axis}[name=axis_2, 
    xmin=-7.5,xmax=7.5, domain=-7:7,
    ymin=-1,ymax=1,
    restrict y to domain=-1:1,
    ticklabel style={font=\tiny},
    ytick={-1,1},
    yticklabels={$-1$, 1},
%
       title = {An illustration of a function with\\
                two extrema: $\boldmath -1$ and $\boldmath1$},
                ]
\addplot[samples=501, domain=-6.28318:6.28318] {sin(deg(x))} 
    node[anchor=south west, pos=0.6875,font=\footnotesize] {$y = \sin{x}$};
    \end{axis}
    \end{tikzpicture}
\end{figure}

\end{document}

在上面的代码中,我做了相同的更改,使其更加简洁。在此,对于图表的标题,我利用了titlle选项pgfplotsset

相关内容