helpers.py
def heat_map(X, x_labels, y_labels, title=None, sort_f=True, print_num=True,
             figsize=None):
    """
    Plots a heat map showing the composition of components.
    Code is adapted from:
    https://matplotlib.org/gallery/images_contours_and_fields/image_annotated_heatmap.html

    Parameters
    ----------
    X : np.ndarray
        The ndarray of heatmap values.
    x_labels : List of strings
        Labels for the horizontal axis of the heat map.
    y_labels : List of strings
        Labels for the vertical axis of the heat map.
    title : String
        A title for the plot, optional.
    sort_f : Boolean
        Whether to sort the array columns by the values in the first row, default True.
    print_num : Boolean
        Whether to plot values within the heatmap, default True.
    figsize : tuple
        Tuple of width and height for figure, optional.
    """

    # Sort inputs for better visibility of patterns
    if sort_f == True:
        x_labels = np.array(x_labels)[X[0,:].argsort()]
        X = X[:,X[0,:].argsort()]

    fig, ax = plt.subplots()
    im = ax.imshow(X, cmap='RdBu')

    ax.set_xticks(np.arange(len(x_labels)))
    ax.set_yticks(np.arange(len(y_labels)))
    ax.set_xticklabels(x_labels)
    ax.set_yticklabels(y_labels)

    plt.setp(ax.get_xticklabels(), rotation=45, ha="right",
             rotation_mode="anchor")

    if print_num==True:
        for i in range(len(y_labels)):
            for j in range(len(x_labels)):
                text = ax.text(j, i, np.round(X[i, j],2),
                               ha="center", va="center", color="black",
                               fontsize=8)

    if title is not None:
        ax.set_title(title)
    fig.tight_layout()
    if figsize is not None:
        fig.set_size_inches(figsize)
    plt.show()

    Plots a heat map showing the composition of components.
    Code is adapted from:
    https://matplotlib.org/gallery/images_contours_and_fields/image_annotated_heatmap.html

    Parameters
    ----------
    X : np.ndarray
        The ndarray of heatmap values.
    x_labels : List of strings
        Labels for the horizontal axis of the heat map.
    y_labels : List of strings
        Labels for the vertical axis of the heat map.
    title : String
        A title for the plot, optional.
    sort_f : Boolean
        Whether to sort the array columns by the values in the first row, default True.
    print_num : Boolean
        Whether to plot values within the heatmap, default True.
    figsize : tuple
        Tuple of width and height for figure, optional.
    
Plots a heat map showing the composition of components.
Plots a heat map showing the composition of components .
def heat_map(X, x_labels, y_labels, title=None, sort_f=True, print_num=True,
             figsize=None):
    if sort_f == True:
        x_labels = np.array(x_labels)[X[0,:].argsort()]
        X = X[:,X[0,:].argsort()]
    fig, ax = plt.subplots()
    im = ax.imshow(X, cmap='RdBu')
    ax.set_xticks(np.arange(len(x_labels)))
    ax.set_yticks(np.arange(len(y_labels)))
    ax.set_xticklabels(x_labels)
    ax.set_yticklabels(y_labels)
    plt.setp(ax.get_xticklabels(), rotation=45, ha="right",
             rotation_mode="anchor")
    if print_num==True:
        for i in range(len(y_labels)):
            for j in range(len(x_labels)):
                text = ax.text(j, i, np.round(X[i, j],2),
                               ha="center", va="center", color="black",
                               fontsize=8)
    if title is not None:
        ax.set_title(title)
    fig.tight_layout()
    if figsize is not None:
        fig.set_size_inches(figsize)
    plt.show()
def heat_map ( X , x_labels , y_labels , title = None , sort_f = True , print_num = True , figsize = None ) : if sort_f == True : x_labels = np . array ( x_labels ) [ X [ 0 , : ] . argsort ( ) ] X = X [ : , X [ 0 , : ] . argsort ( ) ] fig , ax = plt . subplots ( ) im = ax . imshow ( X , cmap = 'RdBu' ) ax . set_xticks ( np . arange ( len ( x_labels ) ) ) ax . set_yticks ( np . arange ( len ( y_labels ) ) ) ax . set_xticklabels ( x_labels ) ax . set_yticklabels ( y_labels ) plt . setp ( ax . get_xticklabels ( ) , rotation = 45 , ha = "right" , rotation_mode = "anchor" ) if print_num == True : for i in range ( len ( y_labels ) ) : for j in range ( len ( x_labels ) ) : text = ax . text ( j , i , np . round ( X [ i , j ] , 2 ) , ha = "center" , va = "center" , color = "black" , fontsize = 8 ) if title is not None : ax . set_title ( title ) fig . tight_layout ( ) if figsize is not None : fig . set_size_inches ( figsize ) plt . show ( )
Plots a heat map showing the composition of components.
Plots a heat map showing the composition of components .
"""
    Plots a heat map showing the composition of components.
    Code is adapted from:
    https://matplotlib.org/gallery/images_contours_and_fields/image_annotated_heatmap.html

    Parameters
    ----------
    X : np.ndarray
        The ndarray of heatmap values.
    x_labels : List of strings
        Labels for the horizontal axis of the heat map.
    y_labels : List of strings
        Labels for the vertical axis of the heat map.
    title : String
        A title for the plot, optional.
    sort_f : Boolean
        Whether to sort the array columns by the values in the first row, default True.
    print_num : Boolean
        Whether to plot values within the heatmap, default True.
    figsize : tuple
        Tuple of width and height for figure, optional.
    """ # Sort inputs for better visibility of patterns

X
The ndarray of heatmap values.
The ndarray of heatmap values .
x_labels
Labels for the horizontal axis of the heat map.
Labels for the horizontal axis of the heat map .
y_labels
Labels for the vertical axis of the heat map.
Labels for the vertical axis of the heat map .
title
A title for the plot, optional.
A title for the plot optional .
sort_f
Whether to sort the array columns by the values in the first row, default True.
Whether to sort the array columns by the values in the first row default True .
True
print_num
Whether to plot values within the heatmap, default True.
Whether to plot values within the heatmap default True .
True
figsize
Tuple of width and height for figure, optional.
Tuple of width and height for figure optional .