Is there a simple way to add coordinate (left and bottom) to the grid in tikz?
Asked
Active
Viewed 6,121 times
6
1 Answers
7
I think this is what is wanted:
\documentclass[tikz]{standalone}
\begin{document}
%
\begin{tikzpicture}
% Draw the grid
\tikzset{help lines/.style={color=blue!50}}
\draw[thick,step=1cm,help lines] (0,0) grid (9,9);
\draw[ultra thin,step=.5cm,help lines] (0,0) grid (9,9);
% Draw axes
\draw[ultra thick,-latex] (0,0) -- (10,0);
\draw[ultra thick,-latex] (0,0) -- (0,10);
% the co-ordinates -- major
\foreach \x in {0,1,...,9} { % for x-axis
\draw [thick] (\x,0) -- (\x,-0.2);
}
\foreach \y in {0,1,...,9} { %% for y-axis
\draw [thick] (0,\y) -- (-0.2,\y);
}
% the numbers
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x,-0.3) {\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (-0.3,\y) {\y}; }
% the co-ordinates -- minor
\foreach \x in {.5,1.5,...,8.5} {
\draw [thin] (\x,0) -- (\x,-0.1);
}
\foreach \y in {.5,1.5,...,8.5} {
\draw [thin] (0,\y) -- (-0.1,\y);
}
\end{tikzpicture}
%
\end{document}

-
3Yes this is pretty much what I want to get (without the two axis). But is this really the simplest way to do this? I thought that grid must have some options to get this result. – Per Apr 26 '13 at 16:51
Andrew's answerto http://tex.stackexchange.com/q/39553/3954, which defines agrid with coordinatesstyle which allows you simply to say\draw (-2,-2) to[grid with coordinates] (7,4);– Gonzalo Medina Apr 26 '13 at 17:08