pairing-function.tex 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. \documentclass{standalone}
  2. \usepackage{pgfplots}
  3. \usepackage{sansmath} % for sans serif math
  4. %%%<
  5. % The data files, written on the first run.
  6. \begin{filecontents}{function.data}
  7. # x y
  8. 0 0
  9. 0 1
  10. 1 0
  11. 0 2
  12. 1 1
  13. 2 0
  14. 0 3
  15. 1 2
  16. 2 1
  17. 3 0
  18. 0 4
  19. 1 3
  20. 2 2
  21. 3 1
  22. 4 0
  23. \end{filecontents}
  24. \begin{document}
  25. \begin{tikzpicture}
  26. \begin{axis}[
  27. compat=newest, % for better label placement
  28. font=\sansmath\sffamily, % math and normal text in sans serif
  29. xlabel=$y$, ylabel=$x$, % the label texts
  30. xmin=0, ymin=0, % axis origin
  31. enlarge y limits=false, % don't enlarge the y axis beyond the data range
  32. enlarge x limits={upper,abs=0.02}, % enlarge x axis slightly to make sure the last tick mark is drawn completely
  33. axis lines*=left, % only draw the left axis lines, not a box
  34. unit vector ratio*={1 1 1}, % equal axis scaling. "*" to make sure the axes can only be reduced in size, not enlarged
  35. width=6cm, % set the overall width of the plot
  36. try min ticks=5, % adjusts how many ticks are printed
  37. tick align=center, % tick marks centered on the axes
  38. legend style={
  39. draw=none, % no frame around axes
  40. at={(1,1)}, % place at upper right of plot
  41. anchor=north, % use upper middle edge of legend for alignment
  42. fill=none
  43. },
  44. ]
  45. \addplot [
  46. mark=square*, mark size=0.5em, % square, filled ("*"), radius of 0.5em
  47. nodes near coords={
  48. \pgfmathparse{int(\coordindex)}
  49. \pgfmathresult
  50. }, % print labels on each data point, using `\coordindex` (the data point counter) increased by 1
  51. every node near coord/.style={
  52. font=\scriptsize\sffamily\bfseries, % smaller text size, bold for the data point labels
  53. text=white,
  54. anchor=center % center the labels on the plot marks
  55. }
  56. ] table {function.data};
  57. \addlegendentry{$\displaystyle\pi(x, y) = y + \sum_{i=0}^{x+y} i$}
  58. \end{axis}
  59. \end{tikzpicture}
  60. \end{document}