Skip to content

Instantly share code, notes, and snippets.

@zhezh
Last active May 10, 2020 01:20
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 zhezh/2946a96611f10d99625c07b5efba812b to your computer and use it in GitHub Desktop.
Save zhezh/2946a96611f10d99625c07b5efba812b to your computer and use it in GitHub Desktop.
[plt colormap] #plot #python
# 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