[Tex/LaTex] How to enable minor y ticks for a logarithmic axis

pgfplotstickstikz-pgf

I am using pgfplots to create some plot with logarithmic axis. But Latex automatically shows minor y ticks for some of them and doesn't show them for the others. Here is an example (when I increase the height of the first example, it will show the minor ticks):

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}
            \begin{tikzpicture}
                \begin{axis}[
                        height=5cm,
                        x tick label style={/pgf/number format/1000 sep=},
                        enlargelimits=0,
                        legend style={at={(0.5,0)},
                        anchor=north,legend columns=-1},
                        ymode=log,
                    ]
                    \addplot coordinates {
                        (5,163843)
                        (10,163616)
                        (15,163640)
                        (20,159217)
                        (25,158341)
                        (30,162913)
                        (35,162779)
                        (40,160709)
                        (45,159894)
                        (50,163381)
                    };
                    \addplot coordinates {
                        (5,911)
                        (10,1206)
                        (15,1679)
                        (20,2291)
                        (25,3100)
                        (30,4076)
                        (35,5289)
                        (40,6591)
                        (45,8146)
                        (50,9874)
                    };
                    \addplot coordinates {
                        (5,783)
                        (10,739)
                        (15,754)
                        (20,775)
                        (25,778)
                        (30,761)
                        (35,781)
                        (40,762)
                        (45,751)
                        (50,790)
                    };
                    \addplot coordinates {
                        (5,2284680)
                        (10,2280025)
                        (15,2269464)
                        (20,2292492)
                        (25,2268460)
                        (30,2274311)
                        (35,2270791)
                        (40,2278593)
                        (45,2268868)
                        (50,2277766)
                    };
                    \addplot coordinates {
                        (5,1758)
                        (10,1758)
                        (15,1760)
                        (20,1762)
                        (25,1764)
                        (30,1765)
                        (35,1768)
                        (40,1768)
                        (45,1771)
                        (50,1772)
                    };
                    \addplot coordinates {
                        (5,105)
                        (10,107)
                        (15,110)
                        (20,112)
                        (25,112)
                        (30,107)
                        (35,110)
                        (40,111)
                        (45,110)
                        (50,112)
                    };
                \end{axis}
            \end{tikzpicture}

            \begin{tikzpicture}
                \begin{axis}[
                        height=5cm,
                        x tick label style={/pgf/number format/1000 sep=},
                        enlargelimits=0,
                        ymode=log,
                    ]
                    \addplot coordinates {
                        (5,26465)
                        (10,26452)
                        (15,26579)
                        (20,26468)
                        (25,26464)
                        (30,26579)
                        (35,26410)
                        (40,26459)
                        (45,26406)
                        (50,26447)
                    };
                    \addplot coordinates {
                        (5,120)
                        (10,293)
                        (15,582)
                        (20,982)
                        (25,1497)
                        (30,2122)
                        (35,2864)
                        (40,3718)
                        (45,4693)
                        (50,5776)
                    };
                    \addplot coordinates {
                        (5,73)
                        (10,63)
                        (15,65)
                        (20,71)
                        (25,66)
                        (30,69)
                        (35,71)
                        (40,70)
                        (45,75)
                        (50,73)
                    };
                    \addplot coordinates {
                        (5,215668)
                        (10,216228)
                        (15,216175)
                        (20,214921)
                        (25,213931)
                        (30,215041)
                        (35,214770)
                        (40,213248)
                        (45,212755)
                        (50,215309)
                    };
                    \addplot coordinates {
                        (5,668)
                        (10,675)
                        (15,676)
                        (20,676)
                        (25,677)
                        (30,678)
                        (35,680)
                        (40,679)
                        (45,679)
                        (50,683)
                    };
                    \addplot coordinates {
                        (5,50)
                        (10,54)
                        (15,56)
                        (20,55)
                        (25,55)
                        (30,55)
                        (35,56)
                        (40,56)
                        (45,57)
                        (50,58)
                    };
                \end{axis}
            \end{tikzpicture}
\end{document}

How can I solve this problem and show the minor y ticks without increasing the height of this plot?

Best Answer

PGFPlots only prints minor ticks for logarithmic axes if the distance between consecutive major ticks is exactly one logarithmic unit. For example, consider this minimal example:

\documentclass{article}

\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ymode=log,
    domain=0:5,
    ymin=1e0, ymax=1e7,
    title={\texttt ymin = 1e0, ymax = 1e7}
]
\addplot {10^x)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

If you increase the upper limit to ymax = 1e8, the major ticks would be too close together, so PGFPlots skips every second major tick label and disables the minor ticks in between.

You can tell PGFPlots to accept a smaller distance between the tick labels by setting max space between ticks=20 (default is 35):

\documentclass{article}

\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ymode=log,
    domain=0:5,
    ymin=1e0, ymax=1e8,
    title={\texttt ymin = 1e0, ymax = 1e8, max space between ticks=20},
    max space between ticks=20
]
\addplot {10^x)};
\end{axis}
\end{tikzpicture}
\end{document}