pairing-function.tex 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. ylabel style={rotate=-90},
  31. xmin=0, ymin=0, % axis origin
  32. enlarge y limits=false, % don't enlarge the y axis beyond the data range
  33. enlarge x limits={upper,abs=0}, % enlarge x axis slightly to make sure the last tick mark is drawn completely
  34. xticklabel style={yshift=-1ex},
  35. yticklabel style={xshift=-1ex},
  36. axis lines*=left, % only draw the left axis lines, not a box
  37. unit vector ratio*={1 1 1}, % equal axis scaling. "*" to make sure the axes can only be reduced in size, not enlarged
  38. width=6cm, % set the overall width of the plot
  39. try min ticks=5, % adjusts how many ticks are printed
  40. tick align=center, % tick marks centered on the axes
  41. legend style={
  42. draw=none, % no frame around axes
  43. at={(1,1)}, % place at upper right of plot
  44. anchor=north, % use upper middle edge of legend for alignment
  45. fill=none
  46. },
  47. ]
  48. \addplot [
  49. mark=square*, mark size=0.5em, % square, filled ("*"), radius of 0.5em
  50. nodes near coords={
  51. \pgfmathparse{int(\coordindex)}
  52. \pgfmathresult
  53. }, % print labels on each data point, using `\coordindex` (the data point counter) increased by 1
  54. every node near coord/.style={
  55. font=\scriptsize\sffamily\bfseries, % smaller text size, bold for the data point labels
  56. text=white,
  57. anchor=center % center the labels on the plot marks
  58. }
  59. ] table {function.data};
  60. \addlegendentry{$\displaystyle\pi(x, y) = y + \sum_{i=0}^{x+y} i$}
  61. \end{axis}
  62. \end{tikzpicture}
  63. \end{document}