Can I draw x, y lines with cross marks in Tikz

This is pretty much standard, all you need is a grid and a plot of some marks.

\documentclass[tikz,border=3mm]{standalone}
\makeatletter
\newcommand{\myAlph}[1]{\@Alph{#1}}
\makeatother
\begin{document}
\begin{tikzpicture}
 \draw[dotted] (0,0) grid (4.5,4.5);
 \draw[stealth-stealth] (0,5) node[above]{$y$} |- (5,0) node[right]{$x$};
 \path foreach \X in {1,...,4}
 { (\X,0) node[below] {\myAlph{\X}} (0,\X) node[left] {\myAlph{\the\numexpr\X+4}}};
 \draw plot[only marks,mark=x,mark size=4pt] coordinates
 {(1,1) (2,1) (3,1) (4,1) (2,2) (3,2) (1,3) (2,4) (3,4) (4,4)};
\end{tikzpicture}
\end{document}

enter image description here

ADDENDUM: Really just for fun: symbolic coordinates in plain TikZ. It makes us of the timing of what gets parsed when.

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[declare function={A=1;B=2;C=3;D=4;E=1;F=2;G=3;H=4;}]
 \draw[dotted] (0,0) grid (4.5,4.5);
 \draw[stealth-stealth] (0,5) node[above]{$y$} |- (5,0) node[right]{$x$};
 \path foreach \X in {A,...,D} { (\X,0) node[below] {\X}}
     foreach \X in {E,...,H} { (0,\X) node[left] {\X}};
 \draw plot[only marks,mark=x,mark size=4pt] coordinates
 {(A,E) (B,E) (C,E) (D,E) (B,F) (C,F) (A,G) (B,H) (C,H) (D,H)};
\end{tikzpicture}
\end{document}

enter image description here


If you want a more exhausting answer than @Schrödinger's cat's :), then here what you need using symbolic coordinates:

enter image description here

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        xlabel={$X$},
        ylabel={$Y$},
        axis lines=center,
        symbolic x coords={0,A,B,C,D},
        xmin={0}, xmax={D},
        xtick distance=1,
        symbolic y coords={0,E,F,G,H},
        ymin={0}, ymax={H},
        ytick distance=1,
        grid = both, grid style={dotted,black!50},
        every axis x label/.style={at={(current axis.south east)},right=1mm},
        every axis y label/.style={at={(current axis.north west)},above=1mm},
        enlargelimits={abs=30pt,upper},
        ]
        \addplot [only marks,mark=x,mark size = 4pt] coordinates {
            (A,E) (B,E) (C,E) (D,E) 
            (B,F) (C,F)
            (A,G) 
            (B,H) (C,H) (D,H)
        };
    \end{axis}
\end{tikzpicture}

\end{document}

Tags:

Tikz Styles