1

Does anyone know how to make a pretty visualization of the PDF of multivariate (bivariate for simply) normal distribution, with each variable's distribution is projected, like the below figure? Thanks in advance.

Source of the figure: A 3D plot from this thesis.

2 Answers 2

1

This plot is almost certainly produced using matplotlib. Take a look at their tutorials. Stack Overflow also has a matplotlib tag.

To plot in 3D you need to use the mplot3d toolkit.

Sign up to request clarification or add additional context in comments.

Comments

1

try this script

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np

def gauss1(x):
    return np.exp(-(x**2))

def gauss(x, y):
    return gauss1(x)*gauss1(2*y)

fig = plt.figure()
ax = fig.gca(projection='3d')
x = np.linspace(-3, 3, 100)
y = np.linspace(-3, 3, 100)
X, Y = np.meshgrid(x, y)
Z = gauss(X, Y)

ax.plot_surface(X, Y, Z, rstride=2, cstride=2, alpha=0.4, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='x', offset=-4, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='y', offset=4, cmap=cm.coolwarm)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()

This produces the following result

enter image description here

I am not sure how to plot only the contour lines for the projections, but this should get you started.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.