lda-gauss-2.tex 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. \documentclass[varwidth=true, border=5pt]{article}
  2. \usepackage[active,tightpage]{preview}
  3. \usepackage[latin1]{inputenc}
  4. \usepackage{amsmath}
  5. \usepackage{pgfplots}
  6. \usepackage{tikz}
  7. \usetikzlibrary{arrows,positioning}
  8. \usepackage{helvet}
  9. \usepackage[eulergreek]{sansmath}
  10. \pgfmathdeclarefunction{gauss}{2}{%
  11. \pgfmathparse{1/(sqrt(2*pi*#2))*exp(-((x-#1)^2)/(2*#2))}%
  12. }
  13. % to be used: \gauss(x)(mean)(variance)
  14. \makeatletter \newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis} \makeatother
  15. \pgfplotsset{
  16. tick label style = {font=\sansmath\sffamily},
  17. every axis label/.append style={font=\sffamily\footnotesize},
  18. }
  19. \pgfplotsset{axis line on top/.style={
  20. axis line style=transparent,
  21. ticklabel style=transparent,
  22. tick style=transparent,
  23. axis on top=false,
  24. after end axis/.append code={
  25. \pgfplotsset{axis line style=opaque,
  26. ticklabel style=opaque,
  27. tick style=opaque,
  28. grid=none}
  29. \pgfplotsdrawaxis}
  30. }
  31. }
  32. \newcommand{\meanI}{60}
  33. \newcommand{\meanII}{40}
  34. \newcommand{\varI}{800}
  35. \newcommand{\varII}{100}
  36. \newcommand{\labelheight}{0.03}
  37. \pgfmathsetmacro{\meanIheight}{1/(sqrt(2*pi*\varI))}%
  38. \pgfmathsetmacro{\meanIIheight}{1/(sqrt(2*pi*\varII))}%
  39. \pgfmathsetmacro{\plotheight}{max(\meanIheight, \meanIIheight, \labelheight+0.002)}%
  40. \begin{document}
  41. \begin{preview}
  42. \tikzstyle{plotA}=[ultra thick,red!90!black]
  43. \tikzstyle{plotB}=[ultra thick,cyan!50!black]
  44. \begin{tikzpicture}
  45. \begin{axis}[
  46. width=13.5cm,
  47. height=8.625cm,
  48. % Grid
  49. grid = major,
  50. grid style={thin, dashed},
  51. % size
  52. xmin= 0, % start the diagram at this x-coordinate
  53. xmax= 125, % end the diagram at this x-coordinate
  54. ymin= 0, % start the diagram at this y-coordinate
  55. ymax= \plotheight, % end the diagram at this y-coordinate
  56. % Legende
  57. legend style={
  58. font=\large\sansmath\sffamily,
  59. at={(0.5,-0.18)},
  60. anchor=north,
  61. legend cell align=left,
  62. legend columns=-1,
  63. column sep=0.5cm
  64. },
  65. % Ticks
  66. tick align=inside,
  67. minor tick style={thick},
  68. scaled y ticks = false,
  69. ytick=\empty,
  70. % Axis
  71. axis lines = middle,
  72. axis line style = very thick,
  73. axis line on top,
  74. axis line style = {very thick,shorten <=-0.5\pgflinewidth},
  75. xlabel=$x$,
  76. x label style={at={(axis description cs:0.52,0)},
  77. anchor=north,
  78. font=\boldmath\Large},
  79. ylabel=$f(x)$,
  80. y label style={at={(axis description cs:0,0.5)},
  81. anchor=south,
  82. rotate=90,
  83. font=\boldmath\Large},
  84. ]
  85. % Plots of the distributions
  86. \addplot [domain=0:120,samples=200,plotA] {gauss(\meanI,\varI)};
  87. \addplot [domain=0:120,samples=200,plotB] {gauss(\meanII,\varII)};
  88. % Add labels
  89. \node[plotA,above] at (axis cs:102,0.01){\Large $\mathcal{N}(\meanI,\varI)$};
  90. \node[plotB,above] at (axis cs:20,0.03){\Large $\mathcal{N}(\meanII,\varII)$};
  91. \end{axis}
  92. \end{tikzpicture}
  93. \end{preview}
  94. \end{document}