Last active
October 25, 2018 22:09
-
-
Save oxlade39/aa0f5d64d2392e3387284ad8fc155378 to your computer and use it in GitHub Desktop.
draw a colour map with automatic gradient
This file contains hidden or 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 | |
# 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