Skip to content

Instantly share code, notes, and snippets.

@jsundram
Created January 18, 2013 19:52
Show Gist options
  • Select an option

  • Save jsundram/4567883 to your computer and use it in GitHub Desktop.

Select an option

Save jsundram/4567883 to your computer and use it in GitHub Desktop.

Revisions

  1. jsundram created this gist Jan 18, 2013.
    19 changes: 19 additions & 0 deletions heatmat.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    import matplotlib.pyplot as plt
    import numpy as np
    column_labels = list('ABCD')
    row_labels = list('WXYZ')
    data = np.random.rand(4,4)
    fig, ax = plt.subplots()
    heatmap = ax.pcolor(data, cmap=plt.cm.Blues)

    # put the major ticks at the middle of each cell
    ax.set_xticks(np.arange(data.shape[0])+0.5, minor=False)
    ax.set_yticks(np.arange(data.shape[1])+0.5, minor=False)

    # want a more natural, table-like display
    ax.invert_yaxis()
    ax.xaxis.tick_top()

    ax.set_xticklabels(row_labels, minor=False)
    ax.set_yticklabels(column_labels, minor=False)
    plt.show()