title: Visualizing a multivariate normal distribution with numpy and matplotlib in 3 Dimensions
body: <p>I am trying to visualise a multivariate normal distribution with matplotlib.  I would like to produce something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/5PuaD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5PuaD.jpg" alt="enter image description here"></a></p>
  
  <p>I use the following code:</p>
  
  <pre><code>from mpl_toolkits import mplot3d
  x = np.linspace(-1, 3, 100)
  y = np.linspace(0, 4, 100)
  X, Y = np.meshgrid(x, y)
  Z = np.random.multivariate_normal(mean = [1, 2], cov = np.array([[0.5, 0.25],[0.25, 0.50]]), size = 100000)
  ax = plt.axes(projection='3d')
  ax.plot_surface(X, Y, Z, rstride=1, cstride=1,
                  cmap='viridis', edgecolor='none')
  ax.set_title('surface');
  </code></pre>
  
  <p>But I get the following error message: </p>
  
  <pre><code>...
        7 ax.plot_surface(X, Y, Z, rstride=1, cstride=1,
  ----&gt; 8                 cmap='viridis', edgecolor='none')
  ...
  ValueError: shape mismatch: objects cannot be broadcast to a single shape
  </code></pre>
  
  <p>What is the reason of the error and how my code could be corrected?</p>