mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-19 11:38:05 +02:00
more variables, less manual computation
This commit is contained in:
parent
ac99fd24f0
commit
ddac88526e
6 changed files with 185 additions and 19 deletions
|
@ -20,6 +20,17 @@ every axis label/.append style={font=\sffamily\footnotesize},
|
|||
|
||||
% Thanks to percusse for solving problems with the axis
|
||||
|
||||
\newcommand{\meanI}{80}
|
||||
\newcommand{\meanII}{40}
|
||||
\newcommand{\varI}{100}
|
||||
\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)}%
|
||||
|
||||
\begin{document}
|
||||
\begin{preview}
|
||||
\tikzstyle{plotA}=[ultra thick,red!90!black]
|
||||
|
@ -85,19 +96,17 @@ every axis label/.append style={font=\sffamily\footnotesize},
|
|||
\addplot+[plotA,
|
||||
samples at={70},
|
||||
mark=*,
|
||||
mark options={scale=1, fill=red!90!black}] {gauss(80,100)};
|
||||
mark options={scale=1, fill=red!90!black}] {gauss(\meanI,\varI)};
|
||||
\addplot+[plotB,
|
||||
samples at={70},
|
||||
mark=*,
|
||||
mark options={scale=1, fill=cyan!50!black}] {gauss(40,100)};
|
||||
mark options={scale=1, fill=cyan!50!black}] {gauss(\meanII,\varII)};
|
||||
\coordinate (a) at (axis cs:70,0.024);
|
||||
\draw[black,thick](a |- current plot begin) -- (a);
|
||||
|
||||
% Add labels
|
||||
\node[plotA,above] at (axis cs:102,0.03){\Large $\mathcal{N}(80, 100)$};
|
||||
\node[plotB,above] at (axis cs:20,0.03){\Large $\mathcal{N}(40, 100)$};
|
||||
% \addlegendentry{$\mu=80,\enskip \sigma^2 = 100$}
|
||||
% \addlegendentry{$\mu=40,\enskip \sigma^2 = 100$}
|
||||
\node[plotA,above] at (axis cs:102,\labelheight){\Large $\mathcal{N}(\meanI,\varI)$};
|
||||
\node[plotB,above] at (axis cs:20,\labelheight){\Large $\mathcal{N}(\meanII,\varII)$};
|
||||
\end{axis}
|
||||
\end{tikzpicture}
|
||||
\end{preview}
|
||||
|
|
|
@ -34,6 +34,17 @@ every axis label/.append style={font=\sffamily\footnotesize},
|
|||
}
|
||||
}
|
||||
|
||||
\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)}%
|
||||
|
||||
\begin{document}
|
||||
\begin{preview}
|
||||
\tikzstyle{plotA}=[ultra thick,red!90!black]
|
||||
|
@ -46,10 +57,10 @@ every axis label/.append style={font=\sffamily\footnotesize},
|
|||
grid = major,
|
||||
grid style={thin, dashed},
|
||||
% 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= 0.045, % end the diagram at this y-coordinate
|
||||
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
|
||||
% Legende
|
||||
legend style={
|
||||
font=\large\sansmath\sffamily,
|
||||
|
@ -61,10 +72,8 @@ every axis label/.append style={font=\sffamily\footnotesize},
|
|||
},
|
||||
% Ticks
|
||||
tick align=inside,
|
||||
%minor tick num=3,
|
||||
minor tick style={thick},
|
||||
scaled y ticks = false,
|
||||
% xtick={40,70,80},
|
||||
ytick=\empty,
|
||||
% Axis
|
||||
axis lines = middle,
|
||||
|
@ -83,15 +92,12 @@ every axis label/.append style={font=\sffamily\footnotesize},
|
|||
]
|
||||
|
||||
% Plots of the distributions
|
||||
\addplot [domain=0:120,samples=200,plotA] {gauss(60,800)};
|
||||
\addplot [domain=0:120,samples=200,plotB] {gauss(40,100)};
|
||||
|
||||
\addplot [domain=0:120,samples=200,plotA] {gauss(\meanI,\varI)};
|
||||
\addplot [domain=0:120,samples=200,plotB] {gauss(\meanII,\varII)};
|
||||
|
||||
% Add labels
|
||||
\node[plotA,above] at (axis cs:102,0.01){\Large $\mathcal{N}(60, 800)$};
|
||||
\node[plotB,above] at (axis cs:20,0.03){\Large $\mathcal{N}(40, 100)$};
|
||||
% \addlegendentry{$\mu=80,\enskip \sigma^2 = 100$}
|
||||
% \addlegendentry{$\mu=40,\enskip \sigma^2 = 100$}
|
||||
\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}
|
||||
\end{tikzpicture}
|
||||
\end{preview}
|
||||
|
|
33
tikz/lda-gauss-variance-small/Makefile
Normal file
33
tikz/lda-gauss-variance-small/Makefile
Normal file
|
@ -0,0 +1,33 @@
|
|||
SOURCE = lda-gauss-variance-small
|
||||
DELAY = 80
|
||||
DENSITY = 300
|
||||
WIDTH = 512
|
||||
|
||||
make:
|
||||
pdflatex -shell-escape $(SOURCE).tex -output-format=pdf
|
||||
make clean
|
||||
|
||||
clean:
|
||||
rm -rf $(TARGET) *.class *.html *.log *.aux *.data *.gnuplot
|
||||
|
||||
gif:
|
||||
pdfcrop $(SOURCE).pdf
|
||||
convert -verbose -delay $(DELAY) -loop 0 -density $(DENSITY) $(SOURCE)-crop.pdf $(SOURCE).gif
|
||||
make clean
|
||||
|
||||
png:
|
||||
make
|
||||
make svg
|
||||
inkscape $(SOURCE).svg -w $(WIDTH) --export-png=$(SOURCE).png
|
||||
|
||||
transparentGif:
|
||||
convert $(SOURCE).pdf -transparent white result.gif
|
||||
make clean
|
||||
|
||||
svg:
|
||||
#inkscape $(SOURCE).pdf --export-plain-svg=$(SOURCE).svg
|
||||
pdf2svg $(SOURCE).pdf $(SOURCE)1.svg
|
||||
# Necessary, as pdf2svg does not always create valid svgs:
|
||||
inkscape $(SOURCE)1.svg --export-width=$(WIDTH) --export-plain-svg=$(SOURCE)1.svg
|
||||
rsvg-convert -a -w 720 -f svg $(SOURCE)1.svg -o $(SOURCE).svg
|
||||
rm $(SOURCE)1.svg
|
3
tikz/lda-gauss-variance-small/README.md
Normal file
3
tikz/lda-gauss-variance-small/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
Compiled example
|
||||
----------------
|
||||

|
BIN
tikz/lda-gauss-variance-small/lda-gauss-variance-small.png
Normal file
BIN
tikz/lda-gauss-variance-small/lda-gauss-variance-small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
115
tikz/lda-gauss-variance-small/lda-gauss-variance-small.tex
Normal file
115
tikz/lda-gauss-variance-small/lda-gauss-variance-small.tex
Normal file
|
@ -0,0 +1,115 @@
|
|||
\documentclass[varwidth=true, border=5pt]{article}
|
||||
\usepackage[active,tightpage]{preview}
|
||||
\usepackage[latin1]{inputenc}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{pgfplots}
|
||||
\usepackage{tikz}
|
||||
\usetikzlibrary{arrows,positioning}
|
||||
\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
|
||||
|
||||
\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}
|
||||
}
|
||||
}
|
||||
|
||||
\tikzset{>=latex}
|
||||
|
||||
\newcommand{\meanI}{80}
|
||||
\newcommand{\meanII}{40}
|
||||
\newcommand{\varI}{40}
|
||||
\newcommand{\varII}{40}
|
||||
|
||||
\newcommand{\arrowHeight}{0.02}
|
||||
\newcommand{\labelheight}{0.055}
|
||||
|
||||
\pgfmathsetmacro{\meanIheight}{1/(sqrt(2*pi*\varI))}%
|
||||
\pgfmathsetmacro{\meanIIheight}{1/(sqrt(2*pi*\varII))}%
|
||||
\pgfmathsetmacro{\plotheight}{max(\meanIheight, \meanIIheight, \labelheight+0.002)}%
|
||||
|
||||
\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},
|
||||
% size
|
||||
xmin= 20, % start the diagram at this x-coordinate
|
||||
xmax= 105, % 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
|
||||
% 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,
|
||||
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},
|
||||
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},
|
||||
]
|
||||
|
||||
% Mark means
|
||||
\coordinate (axisOrigin) at (axis cs:0,0);
|
||||
\coordinate (meanA) at (axis cs:\meanI,\meanIheight);
|
||||
\draw[black,thick](meanA |- axisOrigin) -- (meanA);
|
||||
|
||||
\coordinate (meanB) at (axis cs:\meanII,\meanIIheight);
|
||||
\draw[black,thick](meanB |- axisOrigin) -- (meanB);
|
||||
\draw[black,ultra thick,<->](axis cs:{\meanI-sqrt(\varI)}, \arrowHeight) -- (axis cs:{\meanI+sqrt(\varI)},\arrowHeight);
|
||||
|
||||
% Plots of the distributions
|
||||
\addplot [domain=0:120,samples=400,plotA] {gauss(\meanI,\varI)};
|
||||
\addplot [domain=0:120,samples=400,plotB] {gauss(\meanII,\varII)};
|
||||
|
||||
% Add labels
|
||||
\node[plotA,above] at (axis cs:\meanI+11,\labelheight){\Large $\mathcal{N}(\meanI, \varI)$};
|
||||
\node[plotB,above] at (axis cs:\meanII-11,\labelheight){\Large $\mathcal{N}(\meanII, \varII)$};
|
||||
\end{axis}
|
||||
\end{tikzpicture}
|
||||
\end{preview}
|
||||
\end{document}
|
Loading…
Add table
Add a link
Reference in a new issue