I have the following plot
with this latex-source:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>
% The data files, written on the first run.
\begin{filecontents}{function.data}
# n m
1 1
1 2
2 1
1 3
2 2
3 1
1 4
2 3
3 2
4 1
1 5
2 4
3 3
4 2
5 1
\end{filecontents}
\begin{document}
\begin{tikzpicture}[y=.5cm, x=.5cm,font=\sffamily]
%axis
\draw (0,0) -- coordinate (x axis mid) (5,0);
\draw (0,0) -- coordinate (y axis mid) (0,5);
%ticks
\foreach \x in {0,...,5}
\draw (\x,1pt) -- (\x,-3pt)
node[anchor=north] {\x};
\foreach \y in {0,...,5}
\draw (1pt,\y) -- (-3pt,\y)
node[anchor=east] {\y};
%labels
\node[below=0.8cm] at (x axis mid) {n};
\node[rotate=90, above=0.8cm] at (y axis mid) {m};
%plots
\draw plot[mark=square*]
file {function.data};
%legend
\begin{scope}[shift={(4,4)}]
\draw (0,0) --
plot[mark=square*, mark options={fill=black}] (0.25,0) -- (0.5,0)
node[right]{f(m, n)};
\end{scope}
\end{tikzpicture}
\end{document}
Now I would like to place numbers into the marks or replace the marks by numbers. How is this possible?
Best Answer
I would use PGFplots for this, instead of building the plots by hand. In PGFplots, you can use the
nodes near coords
key for generating labels at each data point.Here's your plot reproduced in PGFplots, with the labels.