title: Projecting multivariate distribution to 2d plot?
body: <p>I want to do the same thing as the answer to <a href="https://stackoverflow.com/questions/20170083/plot-a-contour-of-multivariate-normal-pdf-of-a-given-mvn-in-matlab">this</a> question did, but not in MATLAB, but in Python with matplotlib. So far I've completed the 3D plot with the code </p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from scipy.stats import multivariate_normal
  from mpl_toolkits.mplot3d import Axes3D
  
  mu_x = 0
  mu_y = 0
  
  x = np.linspace(-10,10,500)
  y = np.linspace(-10,10,500)
  X, Y = np.meshgrid(x,y)
  pos = np.empty(X.shape + (2,))
  pos[:, :, 0] = X; pos[:, :, 1] = Y
  rv = multivariate_normal([mu_x, mu_y], [[1, 0.8], [0.8, 1]])
  
  fig = plt.figure(figsize=(10,5))
  ax = fig.gca(projection='3d')
  ax.plot_surface(X, Y, rv.pdf(pos),cmap='viridis',linewidth=0)
  ax.set_xlabel('X axis')
  ax.set_ylabel('Y axis')
  ax.set_zlabel('Z axis')
  ax.auto_scale_xyz([-10, 10], [-10, 10], [0, 0.5])
  plt.show()
  </code></pre>
  
  <p>But how can I project this to a 2D contour plot? I'm trying</p>
  
  <pre><code>plt.figure()
  CS = plt.contour(X, Y, rv)
  plt.clabel(CS, inline=1, fontsize=10)
  </code></pre>
  
  <p>but apparently this isn't right, since Z is not an array type (I get the error <code>TypeError: float() argument must be a string or a number</code> for the line <code>CS = plt.contour(X, Y, rv)</code>). How can I project the multivariate distribution to a 2D contour plot? Thank you!</p>