Linear colormap from one rgb color to another
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
from matplotlib.colors import LinearSegmentedColormap | |
def black_to_color(high_color: tuple, low_color: tuple = (0,0,0), name: str = "my_color", steps=256): | |
"Get linear colormap from one rgb color to another, defaulting from black" | |
r1,g1,b1 = low_color | |
r2,g2,b2 = high_color | |
cdict = { | |
'red': [(0.0, r1, r1), | |
(1.0, r2, r2)], | |
'green': [(0.0, g1, g1), | |
(1.0, g2, g2)], | |
'blue': [(0.0, b1, b1), | |
(1.0, b2, b2)]} | |
return LinearSegmentedColormap(name, cdict, N=steps) | |
blue = (0,0,1) # this is RGB for blue | |
cmap = black_to_color(blue) | |
cmap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment