Here is my try:
import umpy as np
import matplotlib.pyplot as plt
mean, cov, n_samples = np.array([0.,0.]), np.array([[1.0,0.5],[0.5,1.0]]), 100
data=np.random.multivariate_normal(mean,cov,size=n_samples)
pdf = np.zeros(data.shape[0])
cons = 1./((2*np.pi)**(data.shape[1]/2.)*np.linalg.det(cov)**(-0.5))
X, Y = np.meshgrid(data.T[0], data.T[1])
def pdf(point):
return cons*np.exp(-np.dot(np.dot((point-mean),np.linalg.inv(cov)),(point-mean).T)/2.)
zs = np.array([pdf(np.array(ponit)) for ponit in zip(np.ravel(X), np.ravel(Y))])
Z = zs.reshape(X.shape)
fig = plt.figure()
ax3D = fig.add_subplot(111, projection='3d')
surf = ax3D.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,linewidth=0, antialiased=Fals)
surf.show()
3D surface plot shows the result but it is a bit bizarre!. Any comment or other solutions are appreciated.
What I expect (and want) is something similar to follow: