# How to draw dimension reduced high dimensional gaussians in 2D for EM algorithm visualization

I'm implementing the EM algorithm. The visualization works for 2D features. I'd like to visualize it for higher dimensional data using dimension reduction(PCA) Here k= 3. Each group of elipses are the gaussians. I'm drawing them with some slightly modified code taken from matplotlib:

from matplotlib.patches import Ellipse
import matplotlib.transforms as transforms

#n_std = 3 : 98.9% of points
def confidence_ellipse(mean_x, mean_y, covariance, ax, n_std=3.0, edgecolor= 'red', **kwargs):
#matplotlib method of drawing confidence elipse from mean and covar

# Calculating the standard deviation of x from
# the squareroot of the variance and multiplying
# with the given number of standard deviations.
scale_x = np.sqrt(covariance[0, 0]) * n_std

# calculating the standard deviation of y
scale_y = np.sqrt(covariance[1, 1]) * n_std

# apply the transformation to make normal elipse into whatever abomination the gaussian is
transf = transforms.Affine2D() \
.rotate_deg(45) \
.scale(scale_x, scale_y) \
.translate(mean_x, mean_y)

# Using a special case to obtain the eigenvalues of this
# two-dimensional dataset.
pearson = covariance[0, 1]/np.sqrt(covariance[0, 0] * covariance[1, 1])
a = np.sqrt(1 + pearson)
b = np.sqrt(1 - pearson)
ellipse = Ellipse((0, 0), width=a * 2, height=b * 2,edgecolor=edgecolor, facecolor=None,fill=None, **kwargs)

ellipse.set_transform(transf + ax.transData)