#!/usr/bin/env python3

import math                        # math
import matplotlib.pyplot as plt    # plotting
import ML_covarianceMatrix as CM   # loading user-defined module


dataMatrix  = CM.testData(0.3*math.pi, 1.0, 9.0, 100)
mean, coVar = CM.covarianceMatrix(dataMatrix)

xEllipse, yEllipse = CM.plotEllipseData(coVar)  # coVar-ellipse

xData = [thisRow[0] for thisRow in dataMatrix]
yData = [thisRow[1] for thisRow in dataMatrix]

Z_90 = math.sqrt(4.601)                      # 90% confidence
Z_95 = math.sqrt(5.991)                      # 95% confidence
Z_99 = math.sqrt(9.210)                      # 99% confidence

xE_90 = [Z_90*xx + mean[0] for xx in xEllipse]
yE_90 = [Z_90*yy + mean[1] for yy in yEllipse]
xE_99 = [Z_99*xx + mean[0] for xx in xEllipse]
yE_99 = [Z_99*yy + mean[1] for yy in yEllipse]

plt.plot(xE_90, yE_90, label="90%")
plt.plot(xE_99, yE_99, label="99%")
plt.plot(xData, yData, "ob", markersize=5)

plt.legend(loc="upper left")
plt.axis('square')                           # square plot
plt.savefig('foo.svg')                       # export figure
plt.show()
