gseapy/plot.py
def heatmap(df, z_score=None, title='', figsize=(5,5), cmap='RdBu_r', 
            xticklabels=True, yticklabels=True, ofname=None, **kwargs):
    """Visualize the dataframe.

    :param df: DataFrame from expression table.
    :param z_score: z_score axis{0, 1}. If None, don't normalize data.
    :param title: gene set name.
    :param outdir: path to save heatmap.
    :param figsize: heatmap figsize.
    :param cmap: matplotlib colormap.
    :param ofname: output file name. If None, don't save figure 

    """
    df = zscore(df, axis=z_score)
    df = df.iloc[::-1]
    # Get the positions and used label for the ticks
    ny, nx = df.shape
    xticks = np.arange(0, nx, 1) + .5
    yticks = np.arange(0, ny, 1) + .5

    # If working on commandline, don't show figure
    if hasattr(sys, 'ps1') and (ofname is None): 
        fig = plt.figure(figsize=figsize)
    else:
        fig = Figure(figsize=figsize)
        canvas = FigureCanvas(fig)
    ax = fig.add_subplot(111)
    vmin = np.percentile(df.min(), 2)
    vmax =  np.percentile(df.max(), 98)
    matrix = ax.pcolormesh(df.values, cmap=cmap, vmin=vmin, vmax=vmax)
    ax.set_ylim([0,len(df)])
    ax.set(xticks=xticks, yticks=yticks)
    ax.set_xticklabels(df.columns.values if xticklabels else '', fontsize=14, rotation=90)
    ax.set_yticklabels(df.index.values if yticklabels else '',  fontsize=14)
    ax.set_title("%s\nHeatmap of the Analyzed Geneset"%title, fontsize=20)
    ax.tick_params(axis='both', which='both', bottom=False, top=False,
                   right=False, left=False)
    # cax=fig.add_axes([0.93,0.25,0.05,0.20])
    # cbar = fig.colorbar(matrix, cax=cax)
    cbar = colorbar(matrix)
    cbar.ax.tick_params(axis='both', which='both', bottom=False, top=False,
                        right=False, left=False)
    for side in ["top", "right", "left", "bottom"]:
        ax.spines[side].set_visible(False)
        cbar.ax.spines[side].set_visible(False)
    # cbar.ax.set_title('',loc='left')

    if ofname is not None: 
        # canvas.print_figure(ofname, bbox_inches='tight', dpi=300)
        fig.savefig(ofname, bbox_inches='tight', dpi=300)
    return
def heatmap(df, z_score=None, title='', figsize=(5,5), cmap='RdBu_r', 
            xticklabels=True, yticklabels=True, ofname=None, **kwargs):
    df = zscore(df, axis=z_score)
    df = df.iloc[::-1]
    # Get the positions and used label for the ticks
    ny, nx = df.shape
    xticks = np.arange(0, nx, 1) + .5
    yticks = np.arange(0, ny, 1) + .5

    # If working on commandline, don't show figure
    if hasattr(sys, 'ps1') and (ofname is None): 
        fig = plt.figure(figsize=figsize)
    else:
        fig = Figure(figsize=figsize)
        canvas = FigureCanvas(fig)
    ax = fig.add_subplot(111)
    vmin = np.percentile(df.min(), 2)
    vmax =  np.percentile(df.max(), 98)
    matrix = ax.pcolormesh(df.values, cmap=cmap, vmin=vmin, vmax=vmax)
    ax.set_ylim([0,len(df)])
    ax.set(xticks=xticks, yticks=yticks)
    ax.set_xticklabels(df.columns.values if xticklabels else '', fontsize=14, rotation=90)
    ax.set_yticklabels(df.index.values if yticklabels else '',  fontsize=14)
    ax.set_title("%s\nHeatmap of the Analyzed Geneset"%title, fontsize=20)
    ax.tick_params(axis='both', which='both', bottom=False, top=False,
                   right=False, left=False)
    # cax=fig.add_axes([0.93,0.25,0.05,0.20])
    # cbar = fig.colorbar(matrix, cax=cax)
    cbar = colorbar(matrix)
    cbar.ax.tick_params(axis='both', which='both', bottom=False, top=False,
                        right=False, left=False)
    for side in ["top", "right", "left", "bottom"]:
        ax.spines[side].set_visible(False)
        cbar.ax.spines[side].set_visible(False)
    # cbar.ax.set_title('',loc='left')

    if ofname is not None: 
        # canvas.print_figure(ofname, bbox_inches='tight', dpi=300)
        fig.savefig(ofname, bbox_inches='tight', dpi=300)
    return
def heatmap ( df , z_score = None , title = '' , figsize = ( 5 , 5 ) , cmap = 'RdBu_r' , xticklabels = True , yticklabels = True , ofname = None , * * kwargs ) : df = zscore ( df , axis = z_score ) df = df . iloc [ : : - 1 ] # Get the positions and used label for the ticks ny , nx = df . shape xticks = np . arange ( 0 , nx , 1 ) + .5 yticks = np . arange ( 0 , ny , 1 ) + .5 # If working on commandline, don't show figure if hasattr ( sys , 'ps1' ) and ( ofname is None ) : fig = plt . figure ( figsize = figsize ) else : fig = Figure ( figsize = figsize ) canvas = FigureCanvas ( fig ) ax = fig . add_subplot ( 111 ) vmin = np . percentile ( df . min ( ) , 2 ) vmax = np . percentile ( df . max ( ) , 98 ) matrix = ax . pcolormesh ( df . values , cmap = cmap , vmin = vmin , vmax = vmax ) ax . set_ylim ( [ 0 , len ( df ) ] ) ax . set ( xticks = xticks , yticks = yticks ) ax . set_xticklabels ( df . columns . values if xticklabels else '' , fontsize = 14 , rotation = 90 ) ax . set_yticklabels ( df . index . values if yticklabels else '' , fontsize = 14 ) ax . set_title ( "%s\nHeatmap of the Analyzed Geneset" % title , fontsize = 20 ) ax . tick_params ( axis = 'both' , which = 'both' , bottom = False , top = False , right = False , left = False ) # cax=fig.add_axes([0.93,0.25,0.05,0.20]) # cbar = fig.colorbar(matrix, cax=cax) cbar = colorbar ( matrix ) cbar . ax . tick_params ( axis = 'both' , which = 'both' , bottom = False , top = False , right = False , left = False ) for side in [ "top" , "right" , "left" , "bottom" ] : ax . spines [ side ] . set_visible ( False ) cbar . ax . spines [ side ] . set_visible ( False ) # cbar.ax.set_title('',loc='left') if ofname is not None : # canvas.print_figure(ofname, bbox_inches='tight', dpi=300) fig . savefig ( ofname , bbox_inches = 'tight' , dpi = 300 ) return
Visualize the dataframe.

    :param df: DataFrame from expression table.
    :param z_score: z_score axis{0, 1}. If None, don't normalize data.
    :param title: gene set name.
    :param outdir: path to save heatmap.
    :param figsize: heatmap figsize.
    :param cmap: matplotlib colormap.
    :param ofname: output file name. If None, don't save figure
Visualize the dataframe .