title: Try 3d plotting probability density function for multivariate normal distribution
body: <p>I have this code adapted from here:<a href="https://scipython.com/blog/visualizing-the-bivariate-gaussian-distribution/" rel="nofollow noreferrer">https://scipython.com/blog/visualizing-the-bivariate-gaussian-distribution/</a>
  to work with my data.</p>
  
  <p>My data</p>
  
  <pre><code>hour    Cost
  20  58.00
  20  336.00
  20  34.50
  20  106.50
  20  118.00
  ...
  11  198.36
  11  276.00
  11  40.00
  11  308.00
  11  140.00
  11  72.00
  11  116.50
  11  290.00
  11  266.00
  11  66.00
  11  100.00
  11  79.00
  11  106.00
  11  160.00
  </code></pre>
  
  <p>My Code:</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt
  from matplotlib import cm
  from mpl_toolkits.mplot3d import Axes3D
  
  from scipy.stats import multivariate_normal
  
  
  dataset=df[['hour','Cost']]
  
  X = dataset.hour.values
  Y = dataset.Cost.values
  
  X, Y = np.meshgrid(X, Y)
  N = len(X)
  
  def estimateGaussian(dataset):
      mu = np.mean(dataset, axis=0)
      sigma = np.cov(dataset.T)
      return mu, sigma
  
  
  mu, Sigma = estimateGaussian(dataset)
  
  pos = np.empty(X.shape + (2,))
  pos[:, :, 0] = X
  pos[:, :, 1] = Y
  
  F = multivariate_normal(pos, mu, Sigma)
  Z = F.pdf(pos)
  
  fig = plt.figure(figsize=(20,10))
  ax = fig.gca(projection='3d')
  ax.plot_surface(X, Y, Z, rstride=3, cstride=3, linewidth=1, antialiased=True,
                  cmap=cm.viridis)
  
  cset = ax.contourf(X, Y, Z, zdir='z', offset=-0.15, cmap=cm.viridis)
  
  # Adjust the limits, ticks and view angle
  ax.set_zlim(-0.15,0.2)
  ax.set_zticks(np.linspace(0,0.2,5))
  ax.view_init(27, 90)
  
  plt.show()
  
  </code></pre>
  
  <p>Suppose hour and cost any random vectors</p>
  
  <ul>
  <li>How do I fix this error?</li>
  </ul>
  
  <pre><code>C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\scipy\stats\_multivariate.py in __init__(self, mean, cov, allow_singular, seed, maxpts, abseps, releps)
      725         self._dist = multivariate_normal_gen(seed)
      726         self.dim, self.mean, self.cov = self._dist._process_parameters(
  --&gt; 727                                                             None, mean, cov)
      728         self.cov_info = _PSD(self.cov, allow_singular=allow_singular)
      729         if not maxpts:
  
  C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\scipy\stats\_multivariate.py in _process_parameters(self, dim, mean, cov)
      397 
      398         if mean.ndim != 1 or mean.shape[0] != dim:
  --&gt; 399             raise ValueError("Array 'mean' must be a vector of length %d." % dim)
      400         if cov.ndim == 0:
      401             cov = cov * np.eye(dim)
  
  ValueError: Array 'mean' must be a vector of length 173873952.
  </code></pre>
  
  <ul>
  <li>How do I know probability for any pair of (hour,Cost) in my data and visualize them?</li>
  </ul>
  
  <p>Sorry for mistakes I am not a native speaker in English.</p>
  
  <p>So my question stayed for a while without an answer,i took @ImportanceOfBeingErnest advice to simplify the example and make it verifiable example:</p>
  
  <p>This is a simple example:</p>
  
  <pre><code>time=[1,2,3,4,5,6]
  cost=[4,5,3,4,8,9]
  var_matrix=np.array([time,cost]).T
  mean = np.mean(var_matrix,axis=0)
  sigma = np.cov(var_matrix.T)
  y = multivariate_normal.pdf(var_matrix, mean=mean, cov=sigma,allow_singular=True)
  </code></pre>
  
  <ul>
  <li>How do plot 3d graph show (cost,time) and probability density value for pairs.</li>
  </ul>
  
  <p>Thanks in advance.</p>