Created
January 18, 2013 19:52
-
-
Save jsundram/4567883 to your computer and use it in GitHub Desktop.
Heatmap in python like this one on flowingdata, see stackoverflow for context: http://stackoverflow.com/questions/14391959/heatmap-in-matplotlib-with-pcolor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment