Skip to content

Commit

Permalink
2d-chi-square-probability-density: Added
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Dec 24, 2019
1 parent f18ae23 commit 2b89fc9
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
Binary file added tikz/2d-chi-square-pdf/2d-chi-squared-pdf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions tikz/2d-chi-square-pdf/2d-chi-squared-pdf.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
\documentclass[border=2pt]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{tikz}
\usepackage{xcolor}
\definecolor{yellow}{HTML}{cccc00}
\definecolor{neongreen}{HTML}{00dd00}
\definecolor{turquoise}{HTML}{00cccc}
\definecolor{lila}{HTML}{aa00aa}


\begin{document}
\pgfplotscreateplotcyclelist{mylist}{%
{yellow},
{neongreen, densely dashed},
{turquoise, dashed},
{blue,densely dotted},
{lila,dotted},
{red,loosely dotted},
{black}}
\begin{tikzpicture}
\begin{axis}[
title=$\chi^2_k$,
legend style={at={(0.95, 0.95), anchor=north west}},
axis x line=middle,
axis y line=middle,
grid = major,
width = 16cm,
height= 9cm,
grid style={dashed, gray!30},
domain = 0.01:8,
restrict y to domain = 0:0.5,
axis background/.style={fill=white},
xlabel=$x$,
ylabel=$f_k(x)$,
tick align=outside,
enlargelimits=true,
every axis plot/.append style={very thick},
cycle list name=mylist
]
\foreach \k in {1, 2, 3, 4, 6, 9} {%
\addplot+[mark={}] gnuplot[raw gnuplot] {%
isint(x) = (int(x)==x);
log2 = 0.693147180559945;
chisq(x,k)=k<=0||!isint(k)?1/0:x<=0?0.0:exp((0.5*k-1.0)*log(x)-0.5*x-lgamma(0.5*k)-k*0.5*log2);
set xrange [1.00000e-5:8];
set yrange [0.00000:0.500000];
samples=800;
plot chisq(x,\k)};
\addlegendentryexpanded{$k = \k$}}
\end{axis}
\end{tikzpicture}
\end{document}
31 changes: 31 additions & 0 deletions tikz/2d-chi-square-pdf/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
SOURCE = 2d-chi-squared-pdf
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).svg
# Necessary, as pdf2svg does not always create valid svgs:
inkscape $(SOURCE).svg --export-plain-svg=$(SOURCE).svg
3 changes: 3 additions & 0 deletions tikz/2d-chi-square-pdf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Compiled example
----------------
![Example](2d-chi-squared-pdf.png)

0 comments on commit 2b89fc9

Please sign in to comment.