Last active
December 11, 2018 10:06
-
-
Save kaedonkers/c8b2aebb5a74ef4d03f61442a1faae20 to your computer and use it in GitHub Desktop.
Matplotlib: Custom cmap for controuf using ListedColormap
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
""" | |
Example courtesy of @pp-mo | |
Use ListedColormap with matplotlib.pyplot.contourf to speficy colour of each filled layer. | |
More information can be found at: | |
https://matplotlib.org/1.5.3/api/colors_api.html#matplotlib.colors.ListedColormap | |
""" | |
import matplotlib.pyplot as plt | |
from matplotlib.colors import ListedColormap | |
data = np.arange(12.).reshape((3,4)) | |
cmap = ListedColormap(('red', 'black', 'yellow', 'magenta')) | |
n_levels = cmap.N - 1 | |
plt.contourf(data, n_levels, cmap=cmap) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment