9

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?

2 Answers 2

11

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}

1
  • I realized what the problem is but I didn't know the solution. Thanks for the complete explanation.
    – orezvani
    Oct 18, 2014 at 15:41
0

you should set yminorticks=true in your axis options, if you want them and false if you don't want them. What I would also recommend you is to set ymin, ymax and ytick manually.

4
  • I've already tried that. However, that one is set to true by default (As you can see in my example, I didn't set anything for the second one).
    – orezvani
    Oct 18, 2014 at 13:29
  • I added the following in the first plot and then I got the minorticks: yminorticks=true, ymin=100, ymax=1e6, ytick={100,1e3,1e4,1e5,1e6},
    – bene
    Oct 18, 2014 at 13:34
  • I tried them and it worked. But I only needed to add ymax=1e6. You may edit the answer so that I can mark as solved. I know that yminorticks=true does not work.
    – orezvani
    Oct 18, 2014 at 13:38
  • But do you know what's the problem with this? In my figures, I set the ymax for some of them and I set yticks for some others to solve the problem. But I really don't know why this happens.
    – orezvani
    Oct 18, 2014 at 13:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .