3

below code does does not draw y minor ticks. I could specify them manually, but would prefer to have them drawn automatically by 'minor y tick num=1'. Also I do not understand why exactly they are not drawn in the example. Can anybody help?

\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}
Milton
  • 55

1 Answers1

2

Just providing the minor x tick num=1 already gives the desired result. But I have given more possibilities in the code below how you can set minor yticks. Have a look there.

% 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}

image showing the result of above code

Stefan Pinnow
  • 29,535