Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. % used PGFPlots v1.14
  2. documentclass[border=5pt]{standalone}
  3. usepackage{pgfplots}
  4. usetikzlibrary{
  5. fit,
  6. shapes,
  7. pgfplots.groupplots,
  8. }
  9. newcommand{dsnfive}{prob5_2.dat}
  10. begin{filecontents*}{dsnfive}
  11. 2 7 4 8
  12. 3 6 5 8
  13. 2 5 9 5
  14. 3 5 9 9
  15. 3 3 9 4
  16. 2 2 8 9
  17. 5 1 8 8
  18. 6 2 6 9
  19. 8 1 7 4
  20. 6 4 4 4
  21. end{filecontents*}
  22. begin{document}
  23. begin{tikzpicture}
  24. begin{axis}[
  25. xmin=1,
  26. xmax=10,
  27. ymin=0,
  28. ymax=10,
  29. legend pos=outer north east, % <-- used predefined command to position legend
  30. only marks,
  31. mark=*,
  32. mark options={
  33. scale=1.2,
  34. },
  35. ]
  36. % store number of data points
  37. pgfplotstablegetrowsof{dsnfive}
  38. pgfmathtruncatemacro{N}{pgfplotsretval-1}
  39.  
  40. addplot+ [
  41. blue,
  42. % -------------------------------------------------------------
  43. % comment this block to hide names of the coords
  44. % -----
  45. % text of node coords should be the same as for the
  46. % corresponding coordinates
  47. nodes near coords=acoordindex,
  48. % increase the distance of the nodes a bit
  49. nodes near coords align={above=1ex},
  50. % -------------------------------------------------------------
  51. ] table [x index=0,y index=1] {dsnfive}
  52. % set a coordinate on each data point
  53. % (needed for the `fit' library solution)
  54. foreach i in {0,...,N} {
  55. coordinate [pos=i/N] (ai)
  56. }
  57. ;
  58. addlegendentry{$class 1$}
  59. addplot+ [
  60. red,
  61. % -------------------------------------------------------------
  62. nodes near coords=bcoordindex,
  63. nodes near coords align={below=1ex},
  64. % -------------------------------------------------------------
  65. ] table [x index=2,y index=3] {dsnfive}
  66. % set a coordinate on each data point
  67. % (needed for the `fit' library solution)
  68. foreach i in {0,...,N} {
  69. coordinate [pos=i/N] (bi)
  70. }
  71. ;
  72. addlegendentry{$class 2$}
  73. addplot[]coordinates{(2,7)}node[pos=0](A){};
  74. node[very thick, draw=green!75!black,circle,fit=(A), fill = red, opacity = 0.2]{};
  75. end{axis}
  76. % now add the circles to the points
  77. foreach i in {a0,b6,b8} {
  78. draw [green!60!black,thick] (i) circle (5pt);
  79. }
  80. end{tikzpicture}
  81. end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement