8

I am attempting to plot a log-log graph with bounds not falling on a factor of 10. In my case, the y-axis goes from ymin=0.3 to ymax=300. As you can see in the screenshot, the minor grid lines for y=100 and 200 are missing. Interestingly, if I set ymax=400, the problem goes away.

Per this question, I know I can manually add grid lines with minor tick={100,200,etc} in the axis options, but this not ideal since the bounds of the graph may need to change, and re-updating the tick list is annoying.

graph

My MWE is below.

\documentclass[letter,landscape]{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}

\begin{tikzpicture}
    \begin{loglogaxis}[
        %
        width=5in, height=4in,
        xmin=0.01, xmax=100,
        domain=0.01:100, 
        log ticks with fixed point,
        extra x ticks ={0.02,0.04,0.06,0.08,0.2,0.4,0.6,0.8,2,4,6,8,20,40,60,80},
        extra x tick labels ={0.02,0.04,0.06,0.08,0.2,0.4,0.6,0.8,2,4,6,8,20,40,60,80},
        x tick label style={rotate=90},
        ymin=0.3, ymax=300,
        log ticks with fixed point,
        extra y ticks ={0.3,0.4,0.6,0.8,2,4,6,8,20,40,60,80,200,300},
        extra y tick labels ={0.3,0.4,0.6,0.8,2,4,6,8,20,40,60,80,200,300},
        grid=minor,
        ]
    \end{loglogaxis}
\end{tikzpicture}

\end{document}
4
  • 1
    Aren't they major ticks? You've set grid=minor, so you only have grid lines for the minor ticks, try grid=both. Commented Jan 30, 2021 at 7:11
  • @Torbjørn T, this does appear to fix it, but I'm not entirely sure why. The user manual for pgfplots doesn't describe the behavior of grids particularly well. Also, if I omit the extra y ticks option, it won't draw grid lines for y=200 on the plot.
    – grfrazee
    Commented Jan 30, 2021 at 16:00
  • Please also see here Commented Jan 31, 2021 at 16:03
  • @Matthias Arras, yes, looks like the same issue.
    – grfrazee
    Commented Jan 31, 2021 at 16:13

1 Answer 1

2
+125

It is imho by design: pgfplots avoids to draw minor ticks at the borders and with your values this part is missing. You can force it to add ticks by enlarging the value, but probably it will break other plots, so it should be done locally:

\documentclass[letter,landscape]{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{etoolbox}
\begin{document}
\begin{tikzpicture}
\makeatletter
\patchcmd\pgfplots@prepare@tick@coordlists@for {\pgfplots@ticknum=\c@pgfplots@ticknum@last}
 {\pgfplots@ticknum=\numexpr\c@pgfplots@ticknum@last+1}{}{\fail}
\makeatother
    \begin{loglogaxis}[
        %
        width=5in, height=4in,
        xmin=0.01, xmax=100,
        domain=0.01:100,
        log ticks with fixed point,
        extra x ticks ={0.02,0.04,0.06,0.08,0.2,0.4,0.6,0.8,2,4,6,8,20,40,60,80},
        extra x tick labels ={0.02,0.04,0.06,0.08,0.2,0.4,0.6,0.8,2,4,6,8,20,40,60,80},
        x tick label style={rotate=90},
        ymin=0.3, ymax=300,
        log ticks with fixed point,
        extra y ticks ={0.3,0.4,0.6,0.8,2,4,6,8,20,40,60,80,200,300},
        extra y tick labels ={0.3,0.4,0.6,0.8,2,4,6,8,20,40,60,80,200,300},
        grid=minor,
        ]
    \end{loglogaxis}
\end{tikzpicture}

\end{document}

You must log in to answer this question.

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