diff --git a/tikz/truncated-normal-distribution-density-function/Makefile b/tikz/truncated-normal-distribution-density-function/Makefile new file mode 100644 index 0000000..7f08c2b --- /dev/null +++ b/tikz/truncated-normal-distribution-density-function/Makefile @@ -0,0 +1,33 @@ +SOURCE = truncated-normal-distribution-density-function +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 *.table + +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).svg + # Necessary, as pdf2svg does not always create valid svgs: + inkscape $(SOURCE).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 diff --git a/tikz/truncated-normal-distribution-density-function/README.md b/tikz/truncated-normal-distribution-density-function/README.md new file mode 100644 index 0000000..5ad2b27 --- /dev/null +++ b/tikz/truncated-normal-distribution-density-function/README.md @@ -0,0 +1,8 @@ +Compiled example +---------------- +![Example](truncated-normal-distribution-density-function.png) + +Requirements +------------ + +LaTeX and `gnuplot` diff --git a/tikz/truncated-normal-distribution-density-function/truncated-normal-distribution-density-function.png b/tikz/truncated-normal-distribution-density-function/truncated-normal-distribution-density-function.png new file mode 100644 index 0000000..745a6c9 Binary files /dev/null and b/tikz/truncated-normal-distribution-density-function/truncated-normal-distribution-density-function.png differ diff --git a/tikz/truncated-normal-distribution-density-function/truncated-normal-distribution-density-function.tex b/tikz/truncated-normal-distribution-density-function/truncated-normal-distribution-density-function.tex new file mode 100644 index 0000000..24c317c --- /dev/null +++ b/tikz/truncated-normal-distribution-density-function/truncated-normal-distribution-density-function.tex @@ -0,0 +1,74 @@ +% used PGFPlots v1.14 +% (inspired by Jake's answer given here +% ) +\documentclass[border=5pt]{standalone} +\usepackage{pgfplots} + \pgfplotsset{ + compat=1.3, + } + % create cycle lists that uses the style from OPs figure + % + \pgfplotscreateplotcyclelist{line styles}{ + black,solid\\ + blue,dashed\\ + red,dotted\\ + orange,dashdotted\\ + } + % define a command which stores all commands that are needed for every + % `raw gnuplot' call + \newcommand*\GnuplotDefs{ + % set number of samples + set samples 50; + % + %%% from + % cumulative distribution function (CDF) of normal distribution + cdfn(x,mu,sd) = 0.5 * ( 1 + erf( (x-mu)/sd/sqrt(2)) ); + % probability density function (PDF) of normal distribution + pdfn(x,mu,sd) = 1/(sd*sqrt(2*pi)) * exp( -(x-mu)^2 / (2*sd^2) ); + % PDF of a truncated normal distribution + tpdfn(x,mu,sd,a,b) = pdfn(x,mu,sd) / ( cdfn(b,mu,sd) - cdfn(a,mu,sd) ); + } +\begin{document} + \begin{tikzpicture} + % define macros which are needed for the axis limits as well as for + % setting the domain of calculation + \pgfmathsetmacro{\xmin}{0} + \pgfmathsetmacro{\xmax}{1} + \begin{axis}[ + xmin=\xmin, + xmax=\xmax, + ymin=0, + %ymax=0.23, + %ytick distance=0.05, + %enlargelimits=0.05, + no markers, + smooth, + % use the above created cycle list ... + cycle list name=line styles, + % ... and append the following style to all `\addplot' calls + every axis plot post/.append style={ + very thick, + }, + yticklabel style={ + /pgf/number format/.cd, + fixed, + fixed zerofill, + precision=2, + }, + xlabel={x}, + ylabel={probability density}, + ] + \addplot gnuplot [raw gnuplot] { + % first call all the "common" definitions + \GnuplotDefs + % and then create the data tables + % in GnuPlot `x` key is identical to PGFPlots `domain` key + plot [x=\xmin:\xmax] tpdfn(x,0.8,0.3, 0, 1); + }; + \addplot gnuplot [raw gnuplot] { + \GnuplotDefs + plot [x=\xmin:\xmax] tpdfn(x,0.7,0.1, 0, 1); + }; + \end{axis} + \end{tikzpicture} +\end{document}