diff --git a/tikz/csv-bivariate-normal-distribution/Makefile b/tikz/csv-bivariate-normal-distribution/Makefile new file mode 100644 index 0000000..6638c1e --- /dev/null +++ b/tikz/csv-bivariate-normal-distribution/Makefile @@ -0,0 +1,35 @@ +SOURCE = csv-bivariate-normal-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 diff --git a/tikz/csv-bivariate-normal-distribution/README.md b/tikz/csv-bivariate-normal-distribution/README.md new file mode 100644 index 0000000..3de7719 --- /dev/null +++ b/tikz/csv-bivariate-normal-distribution/README.md @@ -0,0 +1,3 @@ +Compiled example +---------------- +![Example](csv-bivariate-normal-distribution.png) diff --git a/tikz/csv-bivariate-normal-distribution/create.py b/tikz/csv-bivariate-normal-distribution/create.py new file mode 100755 index 0000000..a0a0fff --- /dev/null +++ b/tikz/csv-bivariate-normal-distribution/create.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +"""Create samples for bivariate distribution""" + +from numpy.random import multivariate_normal, seed + + +def create_data(n): + means = [0.0, 0.0] + cov = [[1.0, 0.7], [0.7, 4.0]] + seed(0) + samples = multivariate_normal(means, cov, n) + with open("data.csv", "w") as f: + f.write("x,y\n") + for datapoint in samples: + f.write("%0.4f,%0.4f\n" % tuple(datapoint)) + + +def get_parser(): + from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter + parser = ArgumentParser(description=__doc__, + formatter_class=ArgumentDefaultsHelpFormatter) + parser.add_argument("-n", + dest="n", + default=5000, + type=int, + help="Number of points to generate") + return parser + + +if __name__ == "__main__": + args = get_parser().parse_args() + create_data(args.n) diff --git a/tikz/csv-bivariate-normal-distribution/csv-bivariate-normal-distribution.png b/tikz/csv-bivariate-normal-distribution/csv-bivariate-normal-distribution.png new file mode 100644 index 0000000..13c930f Binary files /dev/null and b/tikz/csv-bivariate-normal-distribution/csv-bivariate-normal-distribution.png differ diff --git a/tikz/csv-bivariate-normal-distribution/csv-bivariate-normal-distribution.tex b/tikz/csv-bivariate-normal-distribution/csv-bivariate-normal-distribution.tex new file mode 100644 index 0000000..23ee9ee --- /dev/null +++ b/tikz/csv-bivariate-normal-distribution/csv-bivariate-normal-distribution.tex @@ -0,0 +1,34 @@ +\documentclass[varwidth=true, border=2pt]{standalone} +\usepackage[utf8]{inputenc} % this is needed for umlauts +\usepackage[ngerman]{babel} % this is needed for umlauts +\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf +\usepackage[margin=2.5cm]{geometry} %layout + +\usepackage{pgfplots} +\pgfplotsset{compat=newest} +\usetikzlibrary{plotmarks} + +\begin{document} +\tikzset{mark options={line width=0.5pt}} +\begin{tikzpicture} + \begin{axis}[ + width=7.5cm, height=15cm, % size of the image + enlarge x limits=0.05, + enlarge y limits=0.05, + xmin = -5, + xmax = 5, + ymin = -10, + ymax = 10, + % xlabel=x, + % ylabel=y + ] + \addplot[scatter, + only marks, + mark=*, + mark size = 1, + point meta=1, + ] + table [x=x, y=y, col sep=comma] {data.csv}; + \end{axis} +\end{tikzpicture} +\end{document}