mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-19 11:38:05 +02:00
added 3d plot of two gaussian distributions in one plot
This commit is contained in:
parent
44f03eabac
commit
e5a4295969
4 changed files with 120 additions and 0 deletions
BIN
tikz/3d-gaussian-distribution/3d-gaussian-distribution.png
Normal file
BIN
tikz/3d-gaussian-distribution/3d-gaussian-distribution.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 170 KiB |
73
tikz/3d-gaussian-distribution/3d-gaussian-distribution.tex
Normal file
73
tikz/3d-gaussian-distribution/3d-gaussian-distribution.tex
Normal file
|
@ -0,0 +1,73 @@
|
|||
% Thanks to Jake for the template
|
||||
% http://tex.stackexchange.com/a/31715/5645
|
||||
% and the help here
|
||||
% http://tex.stackexchange.com/a/198793/5645
|
||||
\documentclass{standalone}
|
||||
|
||||
\usepackage{pgfplots}
|
||||
\pgfplotsset{compat=1.10}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\pgfplotsset{
|
||||
colormap={whitered}{color(0cm)=(white); color(1cm)=(orange!75!red)},
|
||||
colormap={whiteblue}{color(0cm)=(white); color(1cm)=(blue)},
|
||||
}
|
||||
|
||||
\begin{tikzpicture}[
|
||||
declare function={mu11=60;},
|
||||
declare function={mu12=20;},
|
||||
declare function={sigma11=5;},
|
||||
declare function={sigma12=5;},
|
||||
declare function={mu21=70;},
|
||||
declare function={mu22=40;},
|
||||
declare function={sigma21=5;},
|
||||
declare function={sigma22=5;},
|
||||
declare function={rho=0.8;},
|
||||
declare function={normal(\m,\s)=1/(2*\s*sqrt(pi))*exp(-(x-\m)^2/(2*\s^2));},
|
||||
declare function={bivar(\ma,\sa,\mb,\sb,\rho)=
|
||||
1/(2*pi*\sa*\sb*\rho) * exp(-((x-\ma)^2/\sa^2 + (y-\mb)^2/\sb^2 - (2*\rho*(x-\ma)*(y-\mb))/(\sa*\sb)))/(2*(1-\rho*\rho));}]
|
||||
\begin{axis}[
|
||||
width=15cm,
|
||||
view={-15}{70},
|
||||
enlargelimits=false,
|
||||
grid=major,
|
||||
domain=40:90,
|
||||
y domain=0:60,
|
||||
samples=60,
|
||||
xlabel=$x_1$,
|
||||
ylabel=$x_2$,
|
||||
zlabel={$P$},
|
||||
colorbar,
|
||||
colorbar style={
|
||||
at={(1.1,0)},
|
||||
anchor=south west,
|
||||
height=0.25*\pgfkeysvalueof{/pgfplots/parent axis height},
|
||||
title={$P(x_1,x_2)$}
|
||||
}
|
||||
]
|
||||
\addplot3 [
|
||||
surf,
|
||||
colormap={bluewhitered}{color(0cm)=(blue); color(0.5cm)=(white); color(1cm)=(orange!75!red)},
|
||||
point meta={
|
||||
(
|
||||
bivar(mu11,sigma11,mu12,sigma12,rho)>
|
||||
bivar(mu21,sigma21,mu22,sigma22,rho)?
|
||||
bivar(mu11,sigma11,mu12,sigma12,rho):
|
||||
-bivar(mu21,sigma21,mu22,sigma22,rho)
|
||||
)
|
||||
}
|
||||
] {
|
||||
max(
|
||||
bivar(mu11,sigma11,mu12,sigma12,rho),
|
||||
bivar(mu21,sigma21,mu22,sigma22,rho)
|
||||
)};
|
||||
|
||||
\draw [black!50] (axis cs:-1,0,0) -- (axis cs:4,0,0);
|
||||
\draw [black!50] (axis cs:0,-1,0) -- (axis cs:0,4,0);
|
||||
|
||||
\node at (axis cs:-1,1,0.18) [pin=165:$P(x_1)$] {};
|
||||
\node at (axis cs:1.5,4,0.32) [pin=-15:$P(x_2)$] {};
|
||||
\end{axis}
|
||||
\end{tikzpicture}
|
||||
\end{document}
|
35
tikz/3d-gaussian-distribution/Makefile
Normal file
35
tikz/3d-gaussian-distribution/Makefile
Normal file
|
@ -0,0 +1,35 @@
|
|||
SOURCE = 3d-gaussian-distribution
|
||||
DELAY = 80
|
||||
DENSITY = 300
|
||||
WIDTH = 512
|
||||
|
||||
make:
|
||||
pdflatex $(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:
|
||||
make
|
||||
#inkscape $(SOURCE).pdf --export-plain-svg=$(SOURCE).svg
|
||||
pdf2svg $(SOURCE).pdf $(SOURCE).svg
|
||||
# Necessary, as pdf2svg does not always create valid svgs:
|
||||
inkscape $(SOURCE).svg --export-plain-svg=$(SOURCE).svg
|
||||
rsvg-convert -a -w $(WIDTH) -f svg $(SOURCE).svg -o $(SOURCE)2.svg
|
||||
inkscape $(SOURCE)2.svg --export-plain-svg=$(SOURCE).svg
|
||||
rm $(SOURCE)2.svg
|
12
tikz/3d-gaussian-distribution/README.md
Normal file
12
tikz/3d-gaussian-distribution/README.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
Compiled example
|
||||
----------------
|
||||

|
||||
|
||||
|
||||
Credits
|
||||
-------
|
||||
|
||||
This work was created by Martin Thoma with very much help of Jake:
|
||||
|
||||
* http://tex.stackexchange.com/a/31715/5645
|
||||
* http://tex.stackexchange.com/a/198793/5645
|
Loading…
Add table
Add a link
Reference in a new issue