(df, x_col, y_col, c_col, ratio=0.1, n=1, marker='o', alpha=1, x_label='auto', 
                            y_label='auto', cmap=plt.cm.viridis, size=(8,8), share_axes=False)
return f
Scatter + histogram plots of x and y, e.g. after t-SNE dimensionality reduction.
    Colors are wrong in scatter plot if len(class) < 4. Open issue in matplotlib.
    (See: https://github.com/pandas-dev/pandas/issues/9724)
    
    
    Parameters
    ----------
    df : pd.DataFrame
        Dataframe with our data
    {x,y}_col : str
        Name of a column with {x,y} values
    c_col : str
        Name of a column with classes (basis for hue)
    ratio : float
        Ratio to determine empty space of limits of x/y-axis
    marker : str
        Marker in scatter plot
    n : float
        Number of columns of legend
    alpha : float
        Alpha for scatter plot
    x_label : str
        Label of x-axis, default auto: x_col name
    y_label : str
        Label of y-axis, default auto: y_col name
    cmap : matplotlib.colors.ListedColormap
    size : tuple
Scatter + histogram plots of x and y, e.g. after t-SNE dimensionality reduction.
    Colors are wrong in scatter plot if len(class) < 4. Open issue in matplotlib.
    (See: https://github.com/pandas-dev/pandas/issues/9724)
    
    
    Parameters
    ----------
    df : pd.DataFrame
        Dataframe with our data
    {x,y}_col : str
        Name of a column with {x,y} values
    c_col : str
        Name of a column with classes (basis for hue)
    ratio : float
        Ratio to determine empty space of limits of x/y-axis
    marker : str
        Marker in scatter plot
    n : float
        Number of columns of legend
    alpha : float
        Alpha for scatter plot
    x_label : str
        Label of x-axis, default auto: x_col name
    y_label : str
        Label of y-axis, default auto: y_col name
    cmap : matplotlib.colors.ListedColormap
    size : tuple
Scatter + histogram plots of x and y e . g . after t - SNE dimensionality reduction . Colors are wrong in scatter plot if len ( class ) < 4 . Open issue in matplotlib . ( See : https : // github . com / pandas - dev / pandas / issues / 9724 ) Parameters ---------- df : pd . DataFrame Dataframe with our data { x y } _col : str Name of a column with { x y } values c_col : str Name of a column with classes ( basis for hue ) ratio : float Ratio to determine empty space of limits of x / y - axis marker : str Marker in scatter plot n : float Number of columns of legend alpha : float Alpha for scatter plot x_label : str Label of x - axis default auto : x_col name y_label : str Label of y - axis default auto : y_col name cmap : matplotlib . colors . ListedColormap size : tuple
def plot_class_distribution(df, x_col, y_col, c_col, ratio=0.1, n=1, marker='o', alpha=1, x_label='auto', 
                            y_label='auto', cmap=plt.cm.viridis, size=(8,8), share_axes=False):
    """Scatter + histogram plots of x and y, e.g. after t-SNE dimensionality reduction.
    Colors are wrong in scatter plot if len(class) < 4. Open issue in matplotlib.
    (See: https://github.com/pandas-dev/pandas/issues/9724)
    
    
    Parameters
    ----------
    df : pd.DataFrame
        Dataframe with our data
    {x,y}_col : str
        Name of a column with {x,y} values
    c_col : str
        Name of a column with classes (basis for hue)
    ratio : float
        Ratio to determine empty space of limits of x/y-axis
    marker : str
        Marker in scatter plot
    n : float
        Number of columns of legend
    alpha : float
        Alpha for scatter plot
    x_label : str
        Label of x-axis, default auto: x_col name
    y_label : str
        Label of y-axis, default auto: y_col name
    cmap : matplotlib.colors.ListedColormap
    size : tuple
    
    """
    if y_label is 'auto':
        y_label = y_col
    if x_label is 'auto':
        x_label = x_col    
    
    f, ((h1, xx), (sc, h2)) = plt.subplots(2,2, squeeze=True, sharex=share_axes, sharey=share_axes, figsize=size,
                                           gridspec_kw={'width_ratios': [3, 1], 'height_ratios': [1, 3]})
    f.subplots_adjust(hspace=0.1, wspace=0.1)
    xx.axis('off')

    ratio_xaxis = (max(df[x_col]) - min(df[x_col])) * ratio
    ratio_yaxis = (max(df[y_col]) - min(df[y_col])) * ratio
                  
    x_max = max(df[x_col])+ratio_xaxis
    x_min = min(df[x_col])-ratio_xaxis

    y_max = max(df[y_col])+ratio_yaxis
    y_min = min(df[y_col])-ratio_yaxis

    h1.set_xlim(x_min, x_max)
    h1.xaxis.set_visible(False)
    sc.set_xlim(x_min, x_max)
    sc.set_xlabel(x_label)
    
    h2.set_ylim(y_min, y_max)
    h2.yaxis.set_visible(False)
    sc.set_ylim(y_min, y_max)
    sc.set_ylabel(y_label)
    
    c_unique = np.sort(df[c_col].unique(),)

    h, bins = np.histogram(range(len(cmap.colors)), bins=len(c_unique))  # get equally spaced colors from cmap
    colors = [cmap.colors[int(x)] for x in bins[1:]]
    
    for cl, color in zip(c_unique, colors):
        if len(df[df[c_col] == cl]) > 1:
            sns.kdeplot(df[df[c_col] == cl][x_col], ax=h1, c=color, label=cl, legend=False)  # hist1
            sns.kdeplot(df[df[c_col] == cl][y_col], ax=h2, c=color, vertical=True, label=cl, legend=False)  # hist2
        handles, labels = h1.get_legend_handles_labels()
        h1.legend(handles, labels, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., ncol=n)
        sc.scatter(df[df[c_col] == cl][x_col], df[df[c_col] == cl][y_col], c=color, marker=marker, alpha=alpha)
        
    return f
def plot_class_distribution ( df , x_col , y_col , c_col , ratio = 0.1 , n = 1 , marker = 'o' , alpha = 1 , x_label = 'auto' , y_label = 'auto' , cmap = plt . cm . viridis , size = ( 8 , 8 ) , share_axes = False ) : if y_label is 'auto' : y_label = y_col if x_label is 'auto' : x_label = x_col f , ( ( h1 , xx ) , ( sc , h2 ) ) = plt . subplots ( 2 , 2 , squeeze = True , sharex = share_axes , sharey = share_axes , figsize = size , gridspec_kw = { 'width_ratios' : [ 3 , 1 ] , 'height_ratios' : [ 1 , 3 ] } ) f . subplots_adjust ( hspace = 0.1 , wspace = 0.1 ) xx . axis ( 'off' ) ratio_xaxis = ( max ( df [ x_col ] ) - min ( df [ x_col ] ) ) * ratio ratio_yaxis = ( max ( df [ y_col ] ) - min ( df [ y_col ] ) ) * ratio x_max = max ( df [ x_col ] ) + ratio_xaxis x_min = min ( df [ x_col ] ) - ratio_xaxis y_max = max ( df [ y_col ] ) + ratio_yaxis y_min = min ( df [ y_col ] ) - ratio_yaxis h1 . set_xlim ( x_min , x_max ) h1 . xaxis . set_visible ( False ) sc . set_xlim ( x_min , x_max ) sc . set_xlabel ( x_label ) h2 . set_ylim ( y_min , y_max ) h2 . yaxis . set_visible ( False ) sc . set_ylim ( y_min , y_max ) sc . set_ylabel ( y_label ) c_unique = np . sort ( df [ c_col ] . unique ( ) , ) h , bins = np . histogram ( range ( len ( cmap . colors ) ) , bins = len ( c_unique ) ) # get equally spaced colors from cmap colors = [ cmap . colors [ int ( x ) ] for x in bins [ 1 : ] ] for cl , color in zip ( c_unique , colors ) : if len ( df [ df [ c_col ] == cl ] ) > 1 : sns . kdeplot ( df [ df [ c_col ] == cl ] [ x_col ] , ax = h1 , c = color , label = cl , legend = False ) # hist1 sns . kdeplot ( df [ df [ c_col ] == cl ] [ y_col ] , ax = h2 , c = color , vertical = True , label = cl , legend = False ) # hist2 handles , labels = h1 . get_legend_handles_labels ( ) h1 . legend ( handles , labels , bbox_to_anchor = ( 1.05 , 1 ) , loc = 2 , borderaxespad = 0. , ncol = n ) sc . scatter ( df [ df [ c_col ] == cl ] [ x_col ] , df [ df [ c_col ] == cl ] [ y_col ] , c = color , marker = marker , alpha = alpha ) return f