[Tex/LaTex] Tikz, Grid numbering, repeating structures

tikz-pgf

I am doing this:

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz,amsmath}
\usetikzlibrary{arrows}%
\usepackage[np,autolanguage]{numprint}
\begin{document}

\begin{tikzpicture}%
    \draw[step=1cm,black,thin] (0,0) grid (5,5);
    %\foreach \x in {0, 1,...,5} { \node [anchor=north] at (\x,-0.2) {0.0}; }
    %\foreach \y in {0, 1,...,5} { \node [anchor=east] at (-0.2,\y) {\y}; }
    \node at (-0.5,0) {0.0};
    \node at (-0.5,1) {0.2};
    \node at (-0.5,2) {0.4};
    \node at (-0.5,3) {0.6};
    \node at (-0.5,4) {0.8};
    \node at (-0.5,5) {1.0};
    \node at (0,-0.5) {0.0};
    \node at (1,-0.5) {0.2};
    \node at (2,-0.5) {0.4};
    \node at (3,-0.5) {0.6};
    \node at (4,-0.5) {0.8};
    \node at (5,-0.5) {1.0};
    \draw [fill=black, thin] (0.5,2.5) circle [radius=0.05];
    \draw [fill=black, thin] (1.5,0.5) circle [radius=0.05];
    \draw [fill=black, thin] (2.5,4.5) circle [radius=0.05];
    \draw [fill=black, thin] (3.5,1.5) circle [radius=0.05];
    \draw [fill=black, thin] (4.5,3.5) circle [radius=0.05];
\end{tikzpicture}%

\end{document}

Please tell me there is a better way to number the grids (not numbering individual node) and drawing multiple circles in one go!

Thank you.

Best Answer

Do you want simple foreachs for everything? The same as in your code can be done with

% arara: pdflatex

\documentclass{article}
\usepackage{tikz}

\begin{document}    
\begin{tikzpicture}
    \draw[step=1cm,black,thin] (0,0) grid (5,5);
    \foreach \xtick in {0,...,5} {\pgfmathsetmacro\result{\xtick * .2} \node at (\xtick,-0.5) {\pgfmathprintnumber{\result}}; }
    \foreach \ytick in {0,...,5} {\pgfmathsetmacro\result{\ytick * .2} \node at (-.5,\ytick) {\pgfmathprintnumber{\result}}; }
    \foreach \x/\y in {.5/2.5, 1.5/.5, 2.5/4.5, 3.5/1.5, 4.5/3.5}{\draw [fill=black, thin] (\x,\y) circle [radius=0.05];}
\end{tikzpicture}   
\end{document}

enter image description here

If you want something more clever, you have to explain the technique you want to show here.

Nodes can be placed as below and left as well. No hard coding needed.


If you are going to plot more data, you should go for pgfplots of course:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        ,x=5cm,y=5cm
        ,grid=major
        ,major grid style={thick,black}
        ,xmin=0, xmax=1
        ,ymin=0, ymax=1
        ]
    \addplot[black, mark=*, only marks] table {
        .1 .5 
        .3 .1
        .5 .9
        .7 .3
        .9 .7 
    };
    \end{axis}
\end{tikzpicture}
\end{document}