\documentclass{standalone} \usepackage{pgfplots} \usepackage{sansmath} % for sans serif math %%%< % The data files, written on the first run. \begin{filecontents}{function.data} # x y 0 0 0 1 1 0 0 2 1 1 2 0 0 3 1 2 2 1 3 0 0 4 1 3 2 2 3 1 4 0 \end{filecontents} \begin{document} \begin{tikzpicture} \begin{axis}[ compat=newest, % for better label placement font=\sansmath\sffamily, % math and normal text in sans serif xlabel=$y$, ylabel=$x$, % the label texts ylabel style={rotate=-90}, xmin=0, ymin=0, % axis origin enlarge y limits=false, % don't enlarge the y axis beyond the data range enlarge x limits={upper,abs=0}, % enlarge x axis slightly to make sure the last tick mark is drawn completely xticklabel style={yshift=-1ex}, yticklabel style={xshift=-1ex}, axis lines*=left, % only draw the left axis lines, not a box unit vector ratio*={1 1 1}, % equal axis scaling. "*" to make sure the axes can only be reduced in size, not enlarged width=6cm, % set the overall width of the plot try min ticks=5, % adjusts how many ticks are printed tick align=center, % tick marks centered on the axes legend style={ draw=none, % no frame around axes at={(1,1)}, % place at upper right of plot anchor=north, % use upper middle edge of legend for alignment fill=none }, ] \addplot [ mark=square*, mark size=0.5em, % square, filled ("*"), radius of 0.5em nodes near coords={ \pgfmathparse{int(\coordindex)} \pgfmathresult }, % print labels on each data point, using `\coordindex` (the data point counter) increased by 1 every node near coord/.style={ font=\scriptsize\sffamily\bfseries, % smaller text size, bold for the data point labels text=white, anchor=center % center the labels on the plot marks } ] table {function.data}; \addlegendentry{$\displaystyle\pi(x, y) = y + \sum_{i=0}^{x+y} i$} \end{axis} \end{tikzpicture} \end{document}