pgfplots:小 y 刻度不显示

pgfplots:小 y 刻度不显示

下面的代码没有绘制 y 次要刻度。我可以手动指定它们,但更希望通过“minor y tick num=1”自动绘制它们。另外,我不明白为什么它们没有在示例中绘​​制出来。有人能帮忙吗?

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    grid=major,
    minor x tick num=1,
    minor y tick num=1,
    xtick={0,10,...,40},
    ytick={0,0.2,...,1},
%   minor ytick={0.1,0.3,...,0.9},
    xmin=0,
    xmax=40,
    ymin=0,
    ymax=1,
    ]
\end{axis}
\end{tikzpicture}
\end{document}

答案1

只需提供minor x tick num=1即可得到所需的结果。但我在下面的代码中提供了更多设置minor yticks 的可能性。请看那里。

% used PGFPlots v1.13
\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
        xmin=0,
        xmax=40,
        ymin=0,
        ymax=1,
        grid=major,
        xtick={0,10,...,40},
        minor x tick num=1,
        % only setting the following key gives the desired result already
        minor y tick num=1,
        % ---------------------------------------------------------------------
%        % I think giving the `ytick's as abbreviated list causes some
%        % rounding problems and that is why the `minor ytick's are not drawn
%        % ...
%        ytick={0,0.2,...,1.0},
%        % ... this is supported by the fact when giving each entry also the
%        % `ytick's are drawn correctly
%        ytick={0,0.2,0.4,0.6,0.8,1.0},
%        % a simpler method to provide an equidistant tick position is using
%        % the following key which then also works fine with the
%        % `minor y tick num' key
%        ytick distance={0.2},
%        % and as you already have found out, this should be the last option
%        % to take into consideration
%        minor ytick={0.1,0.3,...,0.9},
    ]
\end{axis}
\end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容