[Tex/LaTex] Grid dots in pgfplots

pgfplots

How can I generate a multi-resolution dot grid (see image) in pgfplots? The dot grid does not necessarily coincide with the axis ticks.

multi-resolution dot grid

edit: The above plot was created using

\addplot[only marks,mark=*] plot table[row sep=crcr,]{ high res. coordinates }
\addplot[only marks,mark=*] plot table[row sep=crcr,]{ low res. coordinates }

with huge tables of MATLAB-computed coordinates. What I'm looking for in this question, is a way to algorithmically create the dot grid in pgfplots.

Best Answer

With tikz

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
  \begin{tikzpicture}
    \draw (-2.6,-2.6) rectangle (2.6,2.6);
    \foreach \x in {-2,-1,...,2}{
    \draw (\x,-2.4) -- (\x,-2.6)node[below,font=\footnotesize] {\x};
    \draw (\x,2.4) -- (\x,2.6);
    }
    \foreach \y in {-2,-1,...,2}{
    \draw (-2.4,\y) -- (-2.6,\y)node[left,font=\footnotesize] {\y};
    \draw (2.6,\y) -- (2.4,\y);
    }
    \foreach \x in {-2.4,-2.2,...,2.4}{
    \foreach \y in {-2.4,-2.2,...,2.4}{
    \fill[black!30] (\x,\y) circle[radius=0.5pt];
    }}
    \foreach \x in {-2.4,-1.8,...,2.4}{
    \foreach \y in {-2.4,-1.8,...,2.4}{
    \fill[black!80] (\x,\y) circle[radius=0.8pt];
    }}
  \end{tikzpicture}
\end{document}

enter image description here

Using pgfplots.

I took Tarass's answer and added the fots to the back ground so that plots come front.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usetikzlibrary{backgrounds}

\begin{document}

\begin{tikzpicture}

\begin{axis}[xmin=-2.6,xmax=2.6,
    ymin=-2.6,ymax=2.6,
    after end axis/.code={%
    \begin{scope}[on background layer]
    \foreach \x in {-2.4,-2.2,...,2.4}{
    \foreach \y in {-2.4,-2.2,...,2.4}{
    \fill[black!30] (axis cs:\x,\y) circle[radius=0.5pt];
    }}
    \foreach \x in {-2.4,-1.8,...,2.4}{
    \foreach \y in {-2.4,-1.8,...,2.4}{
    \fill[black!80] (axis cs:\x,\y) circle[radius=0.8pt];
    }}
    \end{scope}
    },]
    \addplot {x^2};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

This is some what slower than Christian Feuersänger's approach though.

With \addplot (still slower)

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\begin{document}

\begin{tikzpicture}

\begin{axis}[xmin=-2.6,xmax=2.6,
    ymin=-2.6,ymax=2.6,
    ]
    \foreach \x in {-2.4,-2.2,...,2.4}{
    \foreach \y in {-2.4,-2.2,...,2.4}{
    \addplot[only marks,mark size=0.5pt,black!30] coordinates {(\x,\y)} ;
    }}
    \foreach \x in {-2.4,-1.8,...,2.4}{
    \foreach \y in {-2.4,-1.8,...,2.4}{
    \addplot[only marks,mark size=0.8pt,black!80] coordinates {(\x,\y)} ;
    }}
    \addplot {x^2};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here