#NEWLINE# def assign_sizes( data , aes ) : #NEWLINE# #INDENT# 'Assigns size to the given data based on the aes and adds the right legend\n\n    Parameters\n    ----------\n    data : DataFrame\n        dataframe which should have sizes assigned to\n    aes : aesthetic\n        mapping, including a mapping from sizes to variable\n\n    Returns\n    -------\n    data : DataFrame\n        the changed dataframe\n    legend_entry : dict\n        An entry into the legend dictionary.\n        Documented in `components.legend`\n    ' #NEWLINE# legend_entry = dict ( ) #NEWLINE# if ( 'size' in aes ) : #NEWLINE# #INDENT# size_col = aes [ 'size' ] #NEWLINE# try : #NEWLINE# #INDENT# values = data [ size_col ] . astype ( np . float ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise GgplotError ( ( "Size aesthetic '%s' contains non-numerical data" % size_col ) ) #NEWLINE# #UNINDENT# _min = values . min ( ) #NEWLINE# normalize = ( lambda v : ( 30 + ( ( 200.0 * ( v - _min ) ) / ( v . max ( ) - _min ) ) ) ) #NEWLINE# data [ ':::size_mapping:::' ] = normalize ( values ) #NEWLINE# ( labels , scale_type , indices ) = get_labels ( data , size_col ) #NEWLINE# if ( scale_type == 'continuous' ) : #NEWLINE# #INDENT# quantiles = np . percentile ( data [ ':::size_mapping:::' ] , indices ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( scale_type == 'discrete' ) : #NEWLINE# #INDENT# quantiles = normalize ( np . array ( labels , dtype = np . float ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise GgplotError ( ( "Unknow scale_type: '%s'" % scale_type ) ) #NEWLINE# #UNINDENT# #UNINDENT# legend_entry = { #NEWLINE# #INDENT# 'column_name' : size_col , #NEWLINE# 'dict' : dict ( zip ( quantiles , labels ) ) , #NEWLINE# 'scale_type' : scale_type , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# return ( data , legend_entry )