[Tex/LaTex] Pgfplots: Limiting grid lines or extending arrowhead of x-y axis in simple Cartesian plane

pgfplotstikz-pgf

I am attempting to create a simple Cartesian plane using pgfplots, where the positive ends of the x and y-axis extend slightly past the square grid. So far, what I have is as follows:

enter image description here

\documentclass{article}

\usepackage{tikz, pgfplots}

\begin{document}
\begin{center}
    \begin{tikzpicture}
        \begin{axis}[
            axis lines=middle,
            axis line style=->,
            xmin=-10,xmax=10,
            ymin=-10,ymax=10,
            grid=both,
            grid style={draw=gray!25},
            xtick={-10, -8, ..., 10}, xtick style={yshift=-0.5ex},
            ytick={-10, -8, ..., 10}, ytick style={xshift=-0.5ex},
            yticklabel style={xshift=-0.5ex},
            minor tick num=1,
            minor tick length=0.5ex,
            minor x tick style={yshift=0.25ex}, minor y tick style={xshift=0.25ex},
        ]
        \end{axis}
    \end{tikzpicture}
\end{center}
\end{document}

For reference, here is the template I'm attempting to replicate.

enter image description here

By extending the xmax/ymax values, the grid lines by default extend to these values. Would anyone have any suggestions on either limiting the grid length or extending the positive axis ends?

Best Answer

Welcome! You can use shorten and use a negative distance.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{center}
    \begin{tikzpicture}
        \begin{axis}[
            axis lines=middle,
            axis line style={-stealth,shorten >=-3mm},
            xmin=-10,xmax=10,
            ymin=-10,ymax=10,
            grid=both,
            grid style={draw=gray!25},
            xtick={-10, -8, ..., 10}, xtick style={yshift=-0.5ex},
            ytick={-10, -8, ..., 10}, ytick style={xshift=-0.5ex},
            yticklabel style={xshift=-0.5ex},
            minor tick num=1,
            minor tick length=0.5ex,
            minor x tick style={yshift=0.25ex}, minor y tick style={xshift=0.25ex},
        ]
        \end{axis}
    \end{tikzpicture}
\end{center}
\end{document}

enter image description here

Or with x and y labels.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{center}
    \begin{tikzpicture}
        \begin{axis}[
            axis lines=middle,
            axis line style={-stealth,shorten >=-3mm},
            xmin=-10,xmax=10,
            ymin=-10,ymax=10,
            xlabel=$x$,
            every axis x label/.style={at={(xticklabel cs:1,0)},
            yshift=1.8em,
            anchor=south west},
            ylabel=$y$,
            every axis y label/.style={at={(yticklabel cs:1,0)},
            xshift=2.7em,yshift=0.2em,
            anchor=south east},
            grid=both,
            grid style={draw=gray!25},
            xtick={-10, -8, ..., 10}, xtick style={yshift=-0.5ex},
            ytick={-10, -8, ..., 10}, ytick style={xshift=-0.5ex},
            yticklabel style={xshift=-0.5ex},
            minor tick num=1,
            minor tick length=0.5ex,
            minor x tick style={yshift=0.25ex}, minor y tick style={xshift=0.25ex},
        ]
        \end{axis}
    \end{tikzpicture}
\end{center}
\end{document}

enter image description here