2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-19 11:38:05 +02:00
LaTeX-examples/tikz/lda-gauss-2/lda-gauss-2.tex

105 lines
3.1 KiB
TeX
Raw Permalink Normal View History

2014-08-18 22:03:07 -04:00
\documentclass[varwidth=true, border=5pt]{article}
\usepackage[active,tightpage]{preview}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
2014-08-18 22:03:07 -04:00
\usepackage{helvet}
\usepackage[eulergreek]{sansmath}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(sqrt(2*pi*#2))*exp(-((x-#1)^2)/(2*#2))}%
}
% to be used: \gauss(x)(mean)(variance)
\makeatletter \newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis} \makeatother
2014-08-18 22:03:07 -04:00
\pgfplotsset{
tick label style = {font=\sansmath\sffamily},
every axis label/.append style={font=\sffamily\footnotesize},
}
\pgfplotsset{axis line on top/.style={
axis line style=transparent,
ticklabel style=transparent,
tick style=transparent,
axis on top=false,
after end axis/.append code={
\pgfplotsset{axis line style=opaque,
ticklabel style=opaque,
tick style=opaque,
grid=none}
\pgfplotsdrawaxis}
}
}
\newcommand{\meanI}{60}
\newcommand{\meanII}{40}
\newcommand{\varI}{800}
\newcommand{\varII}{100}
\newcommand{\labelheight}{0.03}
\pgfmathsetmacro{\meanIheight}{1/(sqrt(2*pi*\varI))}%
\pgfmathsetmacro{\meanIIheight}{1/(sqrt(2*pi*\varII))}%
\pgfmathsetmacro{\plotheight}{max(\meanIheight, \meanIIheight, \labelheight+0.002)}%
2014-08-18 22:03:07 -04:00
\begin{document}
\begin{preview}
\tikzstyle{plotA}=[ultra thick,red!90!black]
\tikzstyle{plotB}=[ultra thick,cyan!50!black]
\begin{tikzpicture}
\begin{axis}[
width=13.5cm,
height=8.625cm,
% Grid
grid = major,
grid style={thin, dashed},
2014-08-18 22:03:07 -04:00
% size
xmin= 0, % start the diagram at this x-coordinate
xmax= 125, % end the diagram at this x-coordinate
ymin= 0, % start the diagram at this y-coordinate
ymax= \plotheight, % end the diagram at this y-coordinate
2014-08-18 22:03:07 -04:00
% Legende
legend style={
font=\large\sansmath\sffamily,
at={(0.5,-0.18)},
anchor=north,
legend cell align=left,
legend columns=-1,
column sep=0.5cm
},
% Ticks
tick align=inside,
minor tick style={thick},
scaled y ticks = false,
ytick=\empty,
% Axis
axis lines = middle,
axis line style = very thick,
axis line on top,
axis line style = {very thick,shorten <=-0.5\pgflinewidth},
2014-08-18 22:03:07 -04:00
xlabel=$x$,
x label style={at={(axis description cs:0.52,0)},
anchor=north,
font=\boldmath\Large},
ylabel=$f(x)$,
y label style={at={(axis description cs:0,0.5)},
anchor=south,
rotate=90,
font=\boldmath\Large},
]
% Plots of the distributions
\addplot [domain=0:120,samples=200,plotA] {gauss(\meanI,\varI)};
\addplot [domain=0:120,samples=200,plotB] {gauss(\meanII,\varII)};
2014-08-18 22:03:07 -04:00
% Add labels
\node[plotA,above] at (axis cs:102,0.01){\Large $\mathcal{N}(\meanI,\varI)$};
\node[plotB,above] at (axis cs:20,0.03){\Large $\mathcal{N}(\meanII,\varII)$};
\end{axis}
2014-08-18 22:03:07 -04:00
\end{tikzpicture}
\end{preview}
\end{document}