pgfplots 需要比预期更多的 xticklabels

pgfplots 需要比预期更多的 xticklabels

以下代码在 xticklabels 方面满足了我的要求,但是,我不明白为什么我必须插入 5 个 xticklabels 而不是仅插入 3 个(包括一个幻影标签)才能实现我的目标。有没有更优雅、更易理解的方法?

    \begin{document}
    \usepackage{pgfplots}
    \begin{tikzpicture}
    \begin{axis}[
    axis x line=bottom,
    axis y line=left,
    grid=major, xmin=0, xmax=4,
    xticklabel style = {rotate=90, anchor=east},
    xticklabels = {0,\phantom{0},Chlor,Brom,Jod}
    ]
    \addplot[thick,dashed] coordinates { (0,20) (4,20) };
    \end{axis}
    \end{tikzpicture}
    \end{document}

在此处输入图片描述

答案1

看这个例子,注意第二张图片中,和ticks处没有。如果你想留下一个没有,只需在中留一个空即可。x=0x=4tickticklabel,,ticklabels={...}

\documentclass[tikz]{standalone} 
\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    axis x line=bottom,
    axis y line=left,
    grid=major, xmin=0, xmax=4,
    xticklabel style = {rotate=90, anchor=east},
    xticklabels = {0,\phantom{0},Chlor,Brom,Jod}
    ]
    \addplot[thick,dashed] coordinates { (0,20) (4,20) };
    \end{axis}
    \end{tikzpicture}
    \begin{tikzpicture}
    \begin{axis}[
    axis x line=bottom,
    axis y line=left,
    grid=major, xmin=0, xmax=4,
    xticklabel style = {rotate=90, anchor=east},
    xtick={1,2,3},
    xticklabels = {Chlor,Brom,Jod}
    ]
    \addplot[thick,dashed] coordinates { (0,20) (4,20) };
    \end{axis}
    \end{tikzpicture}
    \begin{tikzpicture}
    \begin{axis}[
    axis x line=bottom,
    axis y line=left,
    grid=major, xmin=0, xmax=4,
    xticklabel style = {rotate=90, anchor=east},
    xtick={1,2,3},
    xticklabels = {Chlor,,Jod}
    ]
    \addplot[thick,dashed] coordinates { (0,20) (4,20) };
    \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容