常规刻度线设置为 draw=none,但额外的刻度线也没有被绘制?

常规刻度线设置为 draw=none,但额外的刻度线也没有被绘制?

在下面的代码中

\documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.17} \definecolor{gold}{RGB}{255, 184, 0}

\begin{document}

\begin{tikzpicture}   \begin{axis}[
    axis lines=center,
    grid=major,
    xmin=-3,
    xmax=3,
    ymin=-3,
    ymax=3,
    width=7cm,
    height=7cm,
    xticklabels={,,},
    yticklabels={,,},
    xtick style={draw=none},
    ytick style={draw=none},
    extra x ticks={-1,1},
    extra x tick labels={,},
    extra x tick style={color=black,grid=none},
    set layers = standard]
    
    \pgfonlayer{axis background}
    \fill[gold!40] (-3,0) -- (3,0) -- (3,3) -- (-3,3);
    \endpgfonlayer
    
    \draw[green, thick] (-3,0) -- (-1,0);
    \draw[green, thick] (1,0) -- (3,0);
    \draw[blue, thick] (-1,0) -- (1,0);
    
    \addplot[smooth, red, thick, domain={0:2}]{sqrt(2.5*x-x^2)};
    
    \node (z3) at (2,1) {\small \textbullet};
    \node at (1.5,1.5) {\scriptsize $\varphi_2^{-1}\circ\varphi_1^{-1}(z_3)$};   \end{axis}    \end{tikzpicture}

\end{document}

在此处输入图片描述

我希望 x 轴上的蓝色和绿色部分之间有两个刻度标记。如果我注释掉该行xtick style={draw=none},,则会出现所有 x 刻度标记,而这并不是我想要的:

在此处输入图片描述

作为参考,我看过在 TikZ/PGF 轴环境中隐藏刻度数。(教我使用draw=none)和删除勾号(pgfplots)(如果我想放入draw=none额外的刻度,我可以,但在这里我想放入draw=none常规刻度并且只看到额外的刻度)。

答案1

您需要在选项major x tick style={draw=black}内进行设置extra x tick style,然后它才能起作用。另请参阅这个答案

\documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.17} \definecolor{gold}{RGB}{255, 184, 0}

\begin{document}

\begin{tikzpicture}   \begin{axis}[
    axis lines=center,
    grid=major,
    xmin=-3,
    xmax=3,
    ymin=-3,
    ymax=3,
    width=7cm,
    height=7cm,
    xticklabels={,,},
    yticklabels={,,},
    x tick style={draw=none},
    y tick style={draw=none},
    extra x ticks={-1,1},
    extra x tick labels={-1,1},
    extra x tick style={major x tick style={draw,black},grid=none},
    set layers = standard]
    
    \pgfonlayer{axis background}
    \fill[gold!40] (-3,0) -- (3,0) -- (3,3) -- (-3,3);
    \endpgfonlayer
    
    \draw[green, thick] (-3,0) -- (-1,0);
    \draw[green, thick] (1,0) -- (3,0);
    \draw[blue, thick] (-1,0) -- (1,0);
    
    \addplot[smooth, red, thick, domain={0:2}]{sqrt(2.5*x-x^2)};
    
    \node (z3) at (2,1) {\small \textbullet};
    \node at (1.5,1.5) {\scriptsize $\varphi_2^{-1}\circ\varphi_1^{-1}(z_3)$};   \end{axis}    \end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容