1

Using pgfplots, I want to have grid lines similar to GeoGebra's. That is four minor ticks in between major ticks and a lighter color for the minor grid lines:

GeoGebra's grid lines

With the help of this post, I managed to get this code

\documentclass[margin=0.5cm]{standalone}
\usepackage{pgfplots}

\begin{document} \begin{tikzpicture} \begin{axis}[ axis lines=center, grid=both, xtick distance=1, ytick distance=1, xmin=-3.5, xmax=3.5, ymin=-3.5, ymax=3.5, x=1cm, y=1cm, xlabel={$x$}, ylabel={$y$}, xlabel style={right}, ylabel style={above}, minor tick num=4, every minor tick/.style={minor tick length=0pt} ] \end{axis} \end{tikzpicture} \end{document}

which produces the following result:

pgfplots' grid

However, this still doesn't quite look like the grid lines from GeoGebra. Is there a way to have separate colors for the major and minor grid lines?

Thank you for any help in advance!

1 Answers1

3

In the doc p.372 With major grid style={gray}, minor grid style={gray!50}

\documentclass[margin=0.5cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis lines=center,
        grid=both,
        xtick distance=1,
        ytick distance=1,
        xmin=-3.5,
        xmax=3.5,
        ymin=-3.5,
        ymax=3.5,
        x=1cm,
        y=1cm,
        xlabel={$x$},
        ylabel={$y$},
        xlabel style={right},
        ylabel style={above},
        minor tick num=4,
        every minor tick/.style={minor tick length=0pt},
        %%%
        major grid style={gray}, minor grid style={gray!50}%<-- added
    ]
    \end{axis}
\end{tikzpicture}
\end{document}

An alternative with the package tkz-base

\documentclass[margin=0.5cm]{standalone}
\usepackage{tkz-base}
\begin{document}
\def\tkzCoeffSubColor{20}% instead of 50
\def\tkzCoeffSubLw{0.2}% instead of 0.75
\begin{tikzpicture}
\tkzInit[
    xmin=-3.5,
    xmax=3.5,
    ymin=-3.5,
    ymax=3.5,
]
% we can change the step for the second grid
\tkzGrid[sub,color=orange,
subxstep=.2,subystep=.2]
\tkzAxeXY
\end{tikzpicture}
\end{document}

enter image description here

pascal974
  • 4,652