# tikz: Clipping everything outside the axis

Clipping everything outside the axis is doable in pgfplots, but drawing lattices has not been great for me there because \foreach doesn't quite work inside axis environment. The code I came up with is this:

\begin{tikzpicture}[scale=0.3]
\draw[->, thick] (-15,0)--(15,0);
\draw[->, thick] (0,-15)--(0,15);

%PLOT
\foreach \x in {-5,-4,...,5}
\foreach \y in {-4,-3,...,4}

\end{tikzpicture}


which expectedly yields:

but I'd rather have this if possible:

I could draw huge white rectangles to cover the unwanted points, but that doesn't quite solve the problem, because the figure will occupy too much space.

Sorry if this is duplicate.

Welcome to TeX.SE!

Are you looking for the following result?

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=0.3]
\draw[->, thick] (-15,0)--(15,0);
\draw[->, thick] (0,-15)--(0,15);

%PLOT
\clip (-15,-15) rectangle (15,15);  % <----
\foreach \x in {-5,-4,...,5}
\foreach \y in {-4,-3,...,4}