如何使用 pgfplots 将小刻度与大刻度分开对齐?

如何使用 pgfplots 将小刻度与大刻度分开对齐?

在下面的 MWE 中,我希望主刻度居中对齐,而 x 轴上的次刻度内对齐,但据我从手册中了解到,所有tick align命令都适用于主刻度和次刻度。我如何才能创建功能上等同于 (不存在) 的东西xminortick align=inside

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
        align=center,
        title={Sample Graph},
        axis y line=left,
        axis x line=bottom,
        axis line style={-Latex,shorten >=-10pt},
        ylabel={Height $h$},
        xlabel={Time $t$ (ms)},
        tick style={solid,black},
        major tick length=8pt,
        minor tick length=4pt,
        % If the next key existed, that would be the behavior I'm after
        %xminortick align=inside,
        xmin=0, xmax=500,   
        xtick distance=100,
        ymin=0, ymax=15,
        ytick distance=5,
        minor x tick num=4,
        ]
    \addplot[thick,domain=0:500] {-3*(x-500)*x/12500};
    \end{axis}
    \end{tikzpicture}
\end{document}

当前行为(所有刻度居中对齐):

样本图的 MWE 输出

答案1

像这样吗?

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\pgfplotsset{%
    every minor tick/.append style={yshift=2pt}, 
}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
        align=center,
        title={Sample Graph},
        axis y line=left,
        axis x line=bottom,
        axis line style={-Latex,shorten >=-10pt},
        ylabel={Height $h$},
        xlabel={Time $t$ (ms)},
        tick style={solid,black},
        major tick length=8pt,
        minor tick length=4pt,
        % If the next key existed, that would be the behavior I'm after
        %xminortick align=inside,
        xmin=0, xmax=500,   
        xtick distance=100,
        ymin=0, ymax=15,
        ytick distance=5,
        minor x tick num=4,
        ]
    \addplot[thick,domain=0:500] {-3*(x-500)*x/12500};
    \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容