# Figure using Tikz with level

How to generate f(x)=x curve in Tikz from 0 to 10 with small straight lines at (1,0), (2,0) etc at x axis and (0,1), (0,2) etc at y axis?

-

The easiest solution is to use pgfplots package which is built on top of PGF/TikZ.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
domain=0:10,
mark=none,
samples=11] {x};
\end{axis}
\end{tikzpicture}
\end{document}


See the manual for additional options such as titles, legend,marks etc.

You can also stay in the TikZ notation but your ammunition will be limited.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[domain=0:10,samples=11]
\draw[very thin,color=gray] (-0.1,-1.1) grid (10,10);
\draw[->] (-0.2,0) -- (10.2,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,10.2) node[above] {$f(x)$};
\draw[ultra thick] plot [const plot] (\x,\x);
\end{tikzpicture}
\end{document}


-

If you wish to only use tikz and not pgfplots, here are two methods to get ticks along the axes, which is what I am assuming you are trying to get. I hope the code is self-explanatory.

The code is

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

%method 1 : with a loop
\begin{tikzpicture}

\draw[->] (0,0) -- (10.2,0) node[right] {$x$};
\foreach \k in {1,...,10}{\draw (\k,-0.05) -- ++(0,0.1);}

\draw[->] (0,0) -- (0,10.2) node[left] {$y$};
\foreach \k in {1,...,10}{\draw (-0.05,\k) -- ++(0.1,0);}

\draw[blue,domain=0:10] plot (\x,\x);
\end{tikzpicture}

%method 2 : with a decoration
\begin{tikzpicture}

\draw[->] (0,0) -- (10.2,0) node[right] {$x$};
\draw[decoration={ticks,segment length=1cm,amplitude=2pt},decorate] (0,0) -- (10.2,0);

\draw[->] (0,0) -- (0,10.2) node[left] {$y$};
\draw[decoration={ticks,segment length=1cm,amplitude=2pt},decorate] (0,0) -- (0,10.2);

\draw[blue,domain=0:10] plot (\x,\x);

\end{tikzpicture}

\end{document}


The result is

-
Thank you very much. – user12290 Feb 25 '12 at 16:02