src/f1lib/setup_mpl.py
def heatmap(data, row_labels, col_labels, ax=None,
            cbar_kw={}, cbarlabel="", **kwargs):
    """
    Create a heatmap from a numpy array and two lists of labels.

    Parameters
    ----------
    data
        A 2D numpy array of shape (N, M).
    row_labels
        A list or array of length N with the labels for the rows.
    col_labels
        A list or array of length M with the labels for the columns.
    ax
        A `matplotlib.axes.Axes` instance to which the heatmap is plotted.  If
        not provided, use current axes or create a new one.  Optional.
    cbar_kw
        A dictionary with arguments to `matplotlib.Figure.colorbar`.  Optional.
    cbarlabel
        The label for the colorbar.  Optional.
    **kwargs
        All other arguments are forwarded to `imshow`.
    """

    if not ax:
        ax = plt.gca()

    # Plot the heatmap
    im = ax.imshow(data, **kwargs)

    # We want to show all ticks...
    ax.set_xticks(np.arange(data.shape[1]))
    ax.set_yticks(np.arange(data.shape[0]))
    
    # ... and label them with the respective list entries.
    ax.set_xticklabels(col_labels)
    ax.set_yticklabels(row_labels)

    # Let the horizontal axes labeling appear on top.
    ax.tick_params(top=False, bottom=False,
                   labeltop=True, labelbottom=True)

    # Rotate the tick labels and set their alignment.
    plt.setp(ax.get_xticklabels(), rotation=0, ha="center",
             rotation_mode="anchor")

    # Turn spines off and create white grid.
    ax.spines[:].set_visible(False)

    ax.set_xticks(np.arange(data.shape[1]+1)-.5, minor=True)
    ax.set_yticks(np.arange(data.shape[0]+1)-.5, minor=True)
    ax.grid(which="minor", axis="x", color="black", linestyle='--', linewidth=1)
    ax.grid(which="minor", axis="y", color="black", linestyle='-', linewidth=3)
    ax.tick_params(which="minor", top=False, left=False)

    return im

    Create a heatmap from a numpy array and two lists of labels.

    Parameters
    ----------
    data
        A 2D numpy array of shape (N, M).
    row_labels
        A list or array of length N with the labels for the rows.
    col_labels
        A list or array of length M with the labels for the columns.
    ax
        A `matplotlib.axes.Axes` instance to which the heatmap is plotted.  If
        not provided, use current axes or create a new one.  Optional.
    cbar_kw
        A dictionary with arguments to `matplotlib.Figure.colorbar`.  Optional.
    cbarlabel
        The label for the colorbar.  Optional.
    **kwargs
        All other arguments are forwarded to `imshow`.
    
Create a heatmap from a numpy array and two lists of labels.
Parameters

data
A 2D numpy array of shape (N, M).
row_labels
A list or array of length N with the labels for the rows.
col_labels
A list or array of length M with the labels for the columns.
ax
A `matplotlib.axes.Axes` instance to which the heatmap is plotted.  If
not provided, use current axes or create a new one.  Optional.
cbar_kw
A dictionary with arguments to `matplotlib.Figure.colorbar`.  Optional.
cbarlabel
The label for the colorbar.  Optional.
kwargs
All other arguments are forwarded to `imshow`.
Create a heatmap from a numpy array and two lists of labels . Parameters data A 2D numpy array of shape ( N M ) . row_labels A list or array of length N with the labels for the rows . col_labels A list or array of length M with the labels for the columns . ax A ` matplotlib . axes . Axes ` instance to which the heatmap is plotted . If not provided use current axes or create a new one . Optional . cbar_kw A dictionary with arguments to ` matplotlib . Figure . colorbar ` . Optional . cbarlabel The label for the colorbar . Optional . kwargs All other arguments are forwarded to ` imshow ` .
def heatmap(data, row_labels, col_labels, ax=None,
            cbar_kw={}, cbarlabel="", **kwargs):
    if not ax:
        ax = plt.gca()
    im = ax.imshow(data, **kwargs)
    ax.set_xticks(np.arange(data.shape[1]))
    ax.set_yticks(np.arange(data.shape[0]))
    ax.set_xticklabels(col_labels)
    ax.set_yticklabels(row_labels)
    ax.tick_params(top=False, bottom=False,
                   labeltop=True, labelbottom=True)
    plt.setp(ax.get_xticklabels(), rotation=0, ha="center",
             rotation_mode="anchor")
    ax.spines[:].set_visible(False)
    ax.set_xticks(np.arange(data.shape[1]+1)-.5, minor=True)
    ax.set_yticks(np.arange(data.shape[0]+1)-.5, minor=True)
    ax.grid(which="minor", axis="x", color="black", linestyle='--', linewidth=1)
    ax.grid(which="minor", axis="y", color="black", linestyle='-', linewidth=3)
    ax.tick_params(which="minor", top=False, left=False)
    return im
def heatmap ( data , row_labels , col_labels , ax = None , cbar_kw = { } , cbarlabel = "" , ** kwargs ) : if not ax : ax = plt . gca ( ) im = ax . imshow ( data , ** kwargs ) ax . set_xticks ( np . arange ( data . shape [ 1 ] ) ) ax . set_yticks ( np . arange ( data . shape [ 0 ] ) ) ax . set_xticklabels ( col_labels ) ax . set_yticklabels ( row_labels ) ax . tick_params ( top = False , bottom = False , labeltop = True , labelbottom = True ) plt . setp ( ax . get_xticklabels ( ) , rotation = 0 , ha = "center" , rotation_mode = "anchor" ) ax . spines [ : ] . set_visible ( False ) ax . set_xticks ( np . arange ( data . shape [ 1 ] + 1 ) - .5 , minor = True ) ax . set_yticks ( np . arange ( data . shape [ 0 ] + 1 ) - .5 , minor = True ) ax . grid ( which = "minor" , axis = "x" , color = "black" , linestyle = '--' , linewidth = 1 ) ax . grid ( which = "minor" , axis = "y" , color = "black" , linestyle = '-' , linewidth = 3 ) ax . tick_params ( which = "minor" , top = False , left = False ) return im
Create a heatmap from a numpy array and two lists of labels.
Create a heatmap from a numpy array and two lists of labels .
"""
    Create a heatmap from a numpy array and two lists of labels.

    Parameters
    ----------
    data
        A 2D numpy array of shape (N, M).
    row_labels
        A list or array of length N with the labels for the rows.
    col_labels
        A list or array of length M with the labels for the columns.
    ax
        A `matplotlib.axes.Axes` instance to which the heatmap is plotted.  If
        not provided, use current axes or create a new one.  Optional.
    cbar_kw
        A dictionary with arguments to `matplotlib.Figure.colorbar`.  Optional.
    cbarlabel
        The label for the colorbar.  Optional.
    **kwargs
        All other arguments are forwarded to `imshow`.
    """ # Plot the heatmap # We want to show all ticks... # ... and label them with the respective list entries. # Let the horizontal axes labeling appear on top. # Rotate the tick labels and set their alignment. # Turn spines off and create white grid.
data
row_labels
col_labels
ax
cbar_kw
cbarlabel