mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-18 19:18:21 +02:00
csv-bivariate-normal-distribution: added
This commit is contained in:
parent
e7f5c73e2a
commit
47e4e3113a
5 changed files with 106 additions and 0 deletions
35
tikz/csv-bivariate-normal-distribution/Makefile
Normal file
35
tikz/csv-bivariate-normal-distribution/Makefile
Normal file
|
@ -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
|
3
tikz/csv-bivariate-normal-distribution/README.md
Normal file
3
tikz/csv-bivariate-normal-distribution/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
Compiled example
|
||||
----------------
|
||||

|
34
tikz/csv-bivariate-normal-distribution/create.py
Executable file
34
tikz/csv-bivariate-normal-distribution/create.py
Executable file
|
@ -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)
|
Binary file not shown.
After Width: | Height: | Size: 135 KiB |
|
@ -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}
|
Loading…
Add table
Add a link
Reference in a new issue