mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-26 06:48:04 +02:00
added image 'csv-2d-multivariate-distributions'
This commit is contained in:
parent
ddac88526e
commit
5dd282f596
6 changed files with 4162 additions and 0 deletions
40
tikz/csv-2d-gaussian-multivarate-distributions/multivariate-random.py
Executable file
40
tikz/csv-2d-gaussian-multivarate-distributions/multivariate-random.py
Executable file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy
|
||||
import csv
|
||||
|
||||
cov = [[25, 20], [20, 25]] # diagonal covariance, points lie on x or y-axis
|
||||
|
||||
meanI = [70, 40]
|
||||
datapointsI = 2000
|
||||
|
||||
meanII = [60, 20]
|
||||
datapointsII = 2000
|
||||
|
||||
dataI = numpy.random.multivariate_normal(meanI, cov, datapointsI).T
|
||||
x, y = dataI
|
||||
plt.plot(x, y, 'x')
|
||||
|
||||
dataII = numpy.random.multivariate_normal(meanII, cov, datapointsII).T
|
||||
x, y = dataII
|
||||
plt.plot(x, y, 'x')
|
||||
|
||||
plt.axis('equal')
|
||||
plt.show()
|
||||
|
||||
data = []
|
||||
xs, ys = dataI
|
||||
for x, y in zip(xs, ys):
|
||||
data.append([x, y, 'a'])
|
||||
xs, ys = dataII
|
||||
for x, y in zip(xs, ys):
|
||||
data.append([x, y, 'b'])
|
||||
|
||||
# Write data to csv files
|
||||
with open("data.csv", 'wb') as csvfile:
|
||||
csvfile.write("x,y,label\n")
|
||||
spamwriter = csv.writer(csvfile, delimiter=',',
|
||||
quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
||||
for datapoint in data:
|
||||
spamwriter.writerow(datapoint)
|
Loading…
Add table
Add a link
Reference in a new issue