How to scale down the size of tick on an axis of graph in Tikz

I put some opacity in the grid. In my opinion, they should also put the red dots in the foreground to hide the dotted lines that invade the dots. But I don't know if you want this.

enter image description here

\documentclass[a4paper, 12pt]{book}
\usepackage{pgfplots, tikz}
\begin{document}
\begin{tikzpicture}[scale = 0.7]
% Draw axes
\draw [<->,thick] (0,5) node (yaxis) [above] {$y$}
|- (5,0) node (xaxis) [right] {$x$};

\coordinate (c) at (2,2);
\fill[red] (c) circle (3pt);
\draw[dashed] (yaxis |- c) node[left] {}
-| (xaxis -| c) node[below] {$\scriptstyle{j-1}$};

\coordinate (d) at (3,2);
\fill[red] (d) circle (3pt);
\draw[dashed] (yaxis |- d) node[left] {$\scriptstyle{i}$}
-| (xaxis -| d) node[below] {};

\coordinate (d) at (3,3);
\fill[red] (d) circle (3pt);
\draw[dashed] (yaxis |- d) node[left] {$\scriptstyle{i+1}$}
-| (xaxis -| d) node[below] {$\scriptstyle{j}$};

\coordinate (d) at (4,2);
\fill[red] (d) circle (3pt);
\draw[dashed] (yaxis |- d) node[left] {}
-| (xaxis -| d) node[below] {$\scriptstyle{j+1}$};

\draw [thin, gray] (0,0) grid (5,5);
\end{tikzpicture}
\end{document}

Scaling elements that contain text is not a good idea, it will result in a suboptimal choice of letter shapes, see Why not scale elements that contain text for more information. Instead of scaling the tick labels, better choose an appropriate font size, e.g. \scriptsize. In case you want specific elements, like x and y to remain in normal size, you can add \normalsize in their nodes.

Some other comments:

  • you print the labels for i and j three times above each other, depending on the rendering precision of your pdf viewer this can cause the font to look awkward, better only print it one time.

  • It would also be better, if you would choose unique names for your coordinates instead of re-using d for 3 of them. This has the big advantage, that you can easily control the order in which you draw things. For example you can first draw the grid in the background, then the axis, the dashed lines and the red dots at the end.

  • To avoid the problem that several dashed with different dash positions are overprinted you could either restrict the drawing range (as done in the example below) or invert the drawing direction to ensure that they all have the same starting point.


\documentclass[a4paper, 12pt]{book}
\usepackage{pgfplots, tikz}
\begin{document}

\begingroup
    \scriptsize
    \begin{tikzpicture}[scale=0.7]

        % grid
        \draw [thin, gray!30] (0,0) grid (5,5);

        % Draw axes
        \draw [<->,thick] (0,5) node (yaxis) [above] {\normalsize $y$} |- (5,0) node (xaxis) [right] {\normalsize $x$};

        % Coordinates   
        \coordinate (a) at (2,2);
        \coordinate (b) at (3,2);
        \coordinate (c) at (3,3);
        \coordinate (d) at (4,2);

        % Dashed lines
        \draw[dashed] (yaxis |- a) node[left] {$i$} -| (xaxis -| a) node[below] {$j-1$};
        \draw[dashed] (a |- b) -| (xaxis -| b) node[below] {$j$};
        \draw[dashed] (yaxis |- c) node[left] {$i+1$} -| (b -| c);
        \draw[dashed] (b |- d) -| (xaxis -| d) node[below] {$j+1$};

        % red dots
        \fill[red] (a) circle (3pt);
        \fill[red] (b) circle (3pt);
        \fill[red] (c) circle (3pt);
        \fill[red] (d) circle (3pt);

    \end{tikzpicture}
\endgroup
\end{document}

enter image description here