dirichlet-function.tex 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. % Thanks to Claudio Fiandrino for his help
  2. % Source: http://tex.stackexchange.com/a/75695/5645
  3. \documentclass{article}
  4. \usepackage[pdftex,active,tightpage]{preview}
  5. \setlength\PreviewBorder{2mm}
  6. \usepackage{amssymb,amsmath}
  7. \usepackage{pgfplots}
  8. \pgfplotsset{compat=1.6}
  9. \begin{document}
  10. \begin{preview}
  11. \begin{tikzpicture}
  12. \begin{axis}[
  13. axis lines=middle,
  14. width=15cm, height=15cm, % size of the image
  15. grid = both,
  16. grid style={dashed, gray!30},
  17. enlargelimits=true,
  18. xmin=-1, % start the diagram at this x-coordinate
  19. xmax= 1, % end the diagram at this x-coordinate
  20. ymin= 0, % start the diagram at this y-coordinate
  21. ymax= 1, % end the diagram at this y-coordinate
  22. /pgfplots/xtick={-1,-0.8,...,1}, % make steps of length 0.2
  23. /pgfplots/ytick={0,0.1,...,1}, % make steps of length 0.1
  24. axis background/.style={fill=white},
  25. ylabel=y,
  26. xlabel=x,]
  27. \addplot[domain=-1:1, ultra thick,samples=100,blue] {1};
  28. \label{plot one}
  29. \addplot[domain=-1:1, ultra thick,samples=100,red] {0};
  30. \label{plot two}
  31. \node [draw,fill=white] at (rel axis cs: 0.8,0.8) {\shortstack[l]{
  32. $f(x) =
  33. \left\lbrace\begin{array}{@{}l@{}l@{}l@{}}
  34. \tikz[baseline=-0.5ex]\node{\ref{plot one}}; \phantom{1cm}& 1 & \text{ if } x \in \mathbb{Q}\\
  35. \tikz[baseline=-0.5ex]\node{\ref{plot two}}; & 0 & \text{ if } x \in \mathbb{R} \setminus \mathbb{Q}
  36. \end{array}\right.
  37. $}};
  38. \end{axis}
  39. \end{tikzpicture}
  40. \end{preview}
  41. \end{document}