topology-metric-hausdorff.tex 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. \documentclass[varwidth=true, border=2pt]{standalone}
  2. \usepackage{pgfplots}
  3. \usepackage{tikz}
  4. \usetikzlibrary{patterns}
  5. % defining the new dimensions and parameters
  6. \newlength{\hatchspread}
  7. \newlength{\hatchthickness}
  8. \newlength{\hatchshift}
  9. \newcommand{\hatchcolor}{}
  10. % declaring the keys in tikz
  11. \tikzset{hatchspread/.code={\setlength{\hatchspread}{#1}},
  12. hatchthickness/.code={\setlength{\hatchthickness}{#1}},
  13. hatchshift/.code={\setlength{\hatchshift}{#1}},% must be >= 0
  14. hatchcolor/.code={\renewcommand{\hatchcolor}{#1}}}
  15. % setting the default values
  16. \tikzset{hatchspread=6pt,
  17. hatchthickness=0.4pt,
  18. hatchshift=0pt,% must be >= 0
  19. hatchcolor=black}
  20. % declaring the pattern
  21. \pgfdeclarepatternformonly[\hatchspread,\hatchthickness,\hatchshift,\hatchcolor]% variables
  22. {custom north west lines}% name
  23. {\pgfqpoint{\dimexpr-2\hatchthickness}{\dimexpr-2\hatchthickness}}% lower left corner
  24. {\pgfqpoint{\dimexpr\hatchspread+2\hatchthickness}{\dimexpr\hatchspread+2\hatchthickness}}% upper right corner
  25. {\pgfqpoint{\dimexpr\hatchspread}{\dimexpr\hatchspread}}% tile size
  26. {% shape description
  27. \pgfsetlinewidth{\hatchthickness}
  28. \pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr\hatchspread+\hatchshift}}
  29. \pgfpathlineto{\pgfqpoint{\dimexpr\hatchspread+0.15pt+\hatchshift}{-0.15pt}}
  30. \ifdim \hatchshift > 0pt
  31. \pgfpathmoveto{\pgfqpoint{0pt}{\hatchshift}}
  32. \pgfpathlineto{\pgfqpoint{\dimexpr0.15pt+\hatchshift}{-0.15pt}}
  33. \fi
  34. \pgfsetstrokecolor{\hatchcolor}
  35. % \pgfsetdash{{1pt}{1pt}}{0pt}% dashing cannot work correctly in all situation this way
  36. \pgfusepath{stroke}
  37. }
  38. \begin{document}
  39. \begin{tikzpicture}
  40. \begin{axis}[
  41. legend pos=south west,
  42. axis x line=middle,
  43. axis y line=middle,
  44. %grid = major,
  45. %width=9cm,
  46. %height=4.5cm,
  47. grid style={dashed, gray!30},
  48. xmin=-1, % start the diagram at this x-coordinate
  49. xmax= 6, % end the diagram at this x-coordinate
  50. ymin=-0.25, % start the diagram at this y-coordinate
  51. ymax= 5, % end the diagram at this y-coordinate
  52. axis background/.style={fill=white},
  53. xlabel=$X_1$,
  54. ylabel=$X_2$,
  55. %xticklabels={,,},
  56. %yticklabels={,,},
  57. %xtick={-1,0,1,2,3,4,5},
  58. %ytick={-1,0,1,2,3,4,5},
  59. ticks=none,
  60. %tick align=outside,
  61. enlargelimits=true,
  62. tension=0.08]
  63. \addplot[hatchcolor=red,mark=none, pattern=custom north west lines, draw=none] coordinates {(0.5, 0) (0.5,5) (1.5,5) (1.5,0) };
  64. \addplot[red,mark=none, thick] coordinates {(0.5, 0) (0.5,5)};
  65. \addplot[red,mark=none, thick] coordinates {(1.5, 0) (1.5,5)};
  66. \addplot[hatchcolor=red,mark=none, pattern=custom north west lines, draw=none] coordinates {(4.5, 0) (4.5,5) (5.5,5) (5.5,0) };
  67. \addplot[red,mark=none, thick] coordinates {(4.5, 0) (4.5,5)};
  68. \addplot[red,mark=none, thick] coordinates {(5.5, 0) (5.5,5)};
  69. \addplot[mark=none, dashed] coordinates {(1, 0) (1,3)};
  70. \addplot[mark=none, dashed] coordinates {(5, 0) (5,3)};
  71. \addplot[mark=x] coordinates {(1, 3)};
  72. \addplot[mark=x] coordinates {(5, 3)};
  73. \node at (axis cs:1,3) [anchor=north west] {$(x_1, y_1)$};
  74. \node at (axis cs:5,3) [anchor=north west] {$(x_2, y_2)$};
  75. \node at (axis cs:1,0) [anchor=north] {$x_1$};
  76. \node at (axis cs:5,0) [anchor=north] {$x_2$};
  77. \node[red] at (axis cs:1,-0.3) [anchor=north] {$U_1 \times X_2$};
  78. \node[red] at (axis cs:5,-0.3) [anchor=north] {$U_2 \times X_2$};
  79. \end{axis}
  80. \end{tikzpicture}
  81. \end{document}