Last active
May 10, 2020 01:20
-
-
Save zhezh/2946a96611f10d99625c07b5efba812b to your computer and use it in GitHub Desktop.
[plt colormap] #plot #python
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
# https://matplotlib.org/3.1.1/gallery/color/colormap_reference.html | |
import numpy as np | |
import matplotlib.pyplot as plt | |
cm = plt.get_cmap('Reds') | |
print(cm.N) # how many color levels in this cm | |
# cm takes list or single value in [0,N-1] or [0.0, 1.0], depending on the value type | |
# value lower or bigger than boundary are default to boundry color | |
cm([-1, 0 ,1, 255, 256]) | |
cm([-1, 0, 0.5, 1, 1.5]) | |
# self defined pure color cmap with alpha changes | |
from matplotlib.colors import ListedColormap | |
pure_colors = [] | |
for i in range(256): | |
pure_colors.append([1.0,0,0, i/255]) | |
pure_colors = np.array(pure_colors) | |
purecm = ListedColormap(pure_colors) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment