如何删除 pgfplots 上的特定刻度?

如何删除 pgfplots 上的特定刻度?

我正在尝试绘制以下图表:


\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=1.5]
\begin{axis}[
    xmin=0, xmax=1,
    ymin=0, ymax=1,
    axis lines=center,
    axis on top=true,
    axis y line=none,
    domain=0:1,
    xtick={0.1, 0.25, 0.4, 0.6, 0.75, 0.9},
    xticklabels={$a_{1}$, $\cdots$ , $a_{n}$, $a^{\prime}_{1}$, $\cdots$ , $a^{\prime}_{m}$}
    ]
    \addplot[mark=none, black, thick] coordinates {(0,0.5) (1,0.5)};
    \addplot[mark=none, black, thick, dotted] coordinates {(0.1,0) (0.1,0.4)};
    \addplot[mark=none, black, thick, dotted] coordinates {(0.4,0) (0.4,0.25)};
    \addplot[mark=none, black, thick, dotted] coordinates {(0.6,0) (0.6,0.65)};
    \addplot[mark=none, black, thick, dotted] coordinates {(0.9,0) (0.9,0.9)};
    \node at (axis cs:0.05, 0.55){$x$};
    \addplot[only marks] 
table {
 0.1 0.4
 0.4 0.25
 0.6 0.65
 0.9 0.9
};
\end{axis}
\end{tikzpicture}

\end{document}

目前的结果如下:

在此处输入图片描述

这几乎就是我想要的,但如果我可以删除省略号上方的勾号会更好:我该怎么做?我尝试使用xtick style={draw=none},但会删除所有勾号。

答案1

正如评论中所建议的那样,尝试使用extra x ticks可以单独设置样式的省略号:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}[scale=1.5]
\begin{axis}[
    xmin=0, xmax=1,
    ymin=0, ymax=1,
    axis lines=center,
    axis on top=true,
    axis y line=none,
    domain=0:1,
    xtick={0.1, 0.4, 0.6, 0.9},
    xticklabels={$a_{1}$, $a_{n}$, $a^{\prime}_{1}$, $a^{\prime}_{m}$},
    extra x ticks={0.25, 0.75},
    extra x tick style={tick style={draw=none}},
    extra x tick labels={$\cdots$, $\cdots$}
]
    \addplot[mark=none, black, thick] coordinates {(0,0.5) (1,0.5)};
    \addplot[mark=none, black, thick, dotted] coordinates {(0.1,0) (0.1,0.4)};
    \addplot[mark=none, black, thick, dotted] coordinates {(0.4,0) (0.4,0.25)};
    \addplot[mark=none, black, thick, dotted] coordinates {(0.6,0) (0.6,0.65)};
    \addplot[mark=none, black, thick, dotted] coordinates {(0.9,0) (0.9,0.9)};
    \node at (0.05, 0.55) {$x$};
    \addplot[only marks] table {
        0.1 0.4
        0.4 0.25
        0.6 0.65
        0.9 0.9
    };
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

还要注意(假设您已安装最新的 TeX)添加允许您在环境内部\pgfplotsset{compat=newest}省略。axis cs:axis

相关内容