bucketplot.py
def expand_lims(df, pct_buffer_below=0.05, pct_buffer_above=0.05, include_vals=None):
    """
    Find the range over all columns of df. Then expand these 
    below and above by a percentage of the total range.
    
    df: Consider all values in all columns
    include_vals: Additional values to consider
    
    Returns: Series with rows 'start' and 'end' of the expanded range
    """
    # If a Series is passed, convert it to a DataFrame
    try:
        df = df.to_frame()
    except:
        pass
    # Case where df has no columns, just fill in default vals
    if df.shape[1] == 0:
        res_range = pd.Series({'start': 0, 'end': 1})
        return(res_range)
    if include_vals is None:
        include_vals = []
    if not isinstance(include_vals, list):
        include_vals = [include_vals]
    
    res_range = pd.concat([
        df.reset_index(drop=True),
        # Add a column of extra values to the DataFrame to take these into account
        pd.DataFrame({'_extra_vals': include_vals}),
    ], axis=1).apply(
        # Get the range (min and max) over the DataFrame
        ['min', 'max']).agg({'min': 'min', 'max': 'max'}, axis=1).agg({
        # Expanded range
        'start': lambda c: c['max'] - (1 + pct_buffer_below) * (c['max'] - c['min']),
        'end': lambda c: c['min'] + (1 + pct_buffer_above) * (c['max'] - c['min']),
    })
    return(res_range)

    Find the range over all columns of df. Then expand these 
    below and above by a percentage of the total range.
    
    df: Consider all values in all columns
    include_vals: Additional values to consider
    
    Returns: Series with rows 'start' and 'end' of the expanded range
    
Find the range over all columns of df. Then expand these
below and above by a percentage of the total range.

Consider all values in all columns
include_vals: Additional values to consider

Series with rows 'start' and 'end' of the expanded range
Find the range over all columns of df . Then expand these below and above by a percentage of the total range . Consider all values in all columns include_vals : Additional values to consider Series with rows ' start ' and ' end ' of the expanded range
def expand_lims(df, pct_buffer_below=0.05, pct_buffer_above=0.05, include_vals=None):
    try:
        df = df.to_frame()
    except:
        pass
    if df.shape[1] == 0:
        res_range = pd.Series({'start': 0, 'end': 1})
        return(res_range)
    if include_vals is None:
        include_vals = []
    if not isinstance(include_vals, list):
        include_vals = [include_vals]
    res_range = pd.concat([
        df.reset_index(drop=True),
        pd.DataFrame({'_extra_vals': include_vals}),
    ], axis=1).apply(
        ['min', 'max']).agg({'min': 'min', 'max': 'max'}, axis=1).agg({
        'start': lambda c: c['max'] - (1 + pct_buffer_below) * (c['max'] - c['min']),
        'end': lambda c: c['min'] + (1 + pct_buffer_above) * (c['max'] - c['min']),
    })
    return(res_range)
def expand_lims ( df , pct_buffer_below = 0.05 , pct_buffer_above = 0.05 , include_vals = None ) : try : df = df . to_frame ( ) except : pass if df . shape [ 1 ] == 0 : res_range = pd . Series ( { 'start' : 0 , 'end' : 1 } ) return ( res_range ) if include_vals is None : include_vals = [ ] if not isinstance ( include_vals , list ) : include_vals = [ include_vals ] res_range = pd . concat ( [ df . reset_index ( drop = True ) , pd . DataFrame ( { '_extra_vals' : include_vals } ) , ] , axis = 1 ) . apply ( [ 'min' , 'max' ] ) . agg ( { 'min' : 'min' , 'max' : 'max' } , axis = 1 ) . agg ( { 'start' : lambda c : c [ 'max' ] - ( 1 + pct_buffer_below ) * ( c [ 'max' ] - c [ 'min' ] ) , 'end' : lambda c : c [ 'min' ] + ( 1 + pct_buffer_above ) * ( c [ 'max' ] - c [ 'min' ] ) , } ) return ( res_range )
Find the range over all columns of df.
Find the range over all columns of df .
"""
    Find the range over all columns of df. Then expand these 
    below and above by a percentage of the total range.
    
    df: Consider all values in all columns
    include_vals: Additional values to consider
    
    Returns: Series with rows 'start' and 'end' of the expanded range
    """ # If a Series is passed, convert it to a DataFrame # Case where df has no columns, just fill in default vals # Add a column of extra values to the DataFrame to take these into account # Get the range (min and max) over the DataFrame # Expanded range
df
pct_buffer_below
pct_buffer_above
include_vals