#NEWLINE# def work( self , fig = None , ax = None ) : #NEWLINE# #INDENT# 'Draw a two dimensional kernel density plot.\n        You can specify either a figure or an axis to draw on.\n\n        Parameters:\n        -----------\n        fig: matplotlib figure object\n        ax: matplotlib axis object to draw on\n\n        Returns:\n        --------\n        fig, ax: matplotlib figure and axis objects\n        ' #NEWLINE# if ( ax is None ) : #NEWLINE# #INDENT# if ( fig is None ) : #NEWLINE# #INDENT# return ( fig , ax ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ax = fig . gca ( ) #NEWLINE# #UNINDENT# #UNINDENT# x = self . data [ self . aes [ 'x' ] ] #NEWLINE# y = self . data [ self . aes [ 'y' ] ] #NEWLINE# x_min = x . min ( ) #NEWLINE# x_max = x . max ( ) #NEWLINE# y_min = y . min ( ) #NEWLINE# y_max = y . max ( ) #NEWLINE# ( X , Y ) = np . mgrid [ x_min : x_max : 200j , y_min : y_max : 200j ] #NEWLINE# positions = np . vstack ( [ X . ravel ( ) , Y . ravel ( ) ] ) #NEWLINE# values = np . vstack ( [ x , y ] ) #NEWLINE# import scipy.stats as stats #NEWLINE# kernel = stats . gaussian_kde ( values ) #NEWLINE# Z = np . reshape ( kernel ( positions ) . T , X . shape ) #NEWLINE# ax . contour ( Z , extent = [ x_min , x_max , y_min , y_max ] ) #NEWLINE# return ( fig , y_min )