Skip to content

Instantly share code, notes, and snippets.

@oxlade39
Last active October 25, 2018 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oxlade39/aa0f5d64d2392e3387284ad8fc155378 to your computer and use it in GitHub Desktop.
Save oxlade39/aa0f5d64d2392e3387284ad8fc155378 to your computer and use it in GitHub Desktop.
draw a colour map with automatic gradient
import matplotlib.pyplot as plt
# generate some example data
matrix = [[1,2,3,4,5,6,7,8,9,10],[1,1,1,1,1,1,1,1,1,1],[5,5,5,5,5,5,5,5,5,5]]
# plot the matrix as an image with an appropriate colormap
plt.imshow(matrix, aspect='auto', cmap="bwr")
# add the values
for nrow in range(0,len(matrix)):
for ncol in range(0, len(matrix[nrow])):
plt.text(ncol, nrow, "%.3f"%matrix[nrow][ncol], va='center', ha='center')
plt.axis('off')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment