def _statsmodels_bivariate_kde(x, y, bw, gridsize, cut, clip):
 if isinstance(bw, string_types):
  bw_func = getattr(smnp.bandwidths, ('bw_' + bw))
  x_bw = bw_func(x)
  y_bw = bw_func(y)
  bw = [x_bw, y_bw]
 elif np.isscalar(bw):
  bw = [bw, bw]
 if isinstance(x, pd.Series):
  x = x.values
 if isinstance(y, pd.Series):
  y = y.values
 kde = smnp.KDEMultivariate([x, y], 'cc', bw)
 x_support = _kde_support(x, kde.bw[0], gridsize, cut, clip[0])
 y_support = _kde_support(y, kde.bw[1], gridsize, cut, clip[1])
 (xx, yy) = np.meshgrid(x_support, y_support)
 z = kde.pdf([xx.ravel(), yy.ravel()]).reshape(xx.shape)
 return (xx, yy, z)

def _statsmodels_bivariate_kde ( x , y , bw , gridsize , cut , clip ) : if isinstance ( bw , string_types ) : bw_func = getattr ( smnp . bandwidths , ( 'bw_' + bw ) ) x_bw = bw_func ( x ) y_bw = bw_func ( y ) bw = [ x_bw , y_bw ] elif np . isscalar ( bw ) : bw = [ bw , bw ] if isinstance ( x , pd . Series ) : x = x . values if isinstance ( y , pd . Series ) : y = y . values kde = smnp . KDEMultivariate ( [ x , y ] , 'cc' , bw ) x_support = _kde_support ( x , kde . bw [ 0 ] , gridsize , cut , clip [ 0 ] ) y_support = _kde_support ( y , kde . bw [ 1 ] , gridsize , cut , clip [ 1 ] ) ( xx , yy ) = np . meshgrid ( x_support , y_support ) z = kde . pdf ( [ xx . ravel ( ) , yy . ravel ( ) ] ) . reshape ( xx . shape ) return ( xx , yy , z )
compute a bivariate kde using statsmodels .