-
-
Save ReneHamburger1993/1ffc005bab5c27e95d2a3e670e7c7864 to your computer and use it in GitHub Desktop.
Nice extra colormaps for matplotlib.
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
class FancyCmaps: | |
""" | |
Useful colormaps for matplotlib. Most importantly: | |
- white_red | |
- white_blue | |
- blue_white | |
- white_black | |
The built-in matplotlib ones don't actually go between pure color values!! | |
For ex, 'Greys' doesn't go from pure white to pure black! | |
So colormaps to consider avoiding include Greys, Blues, Greens, (etc), bwr, and seismic. | |
Matplotlib still has good built-in colormaps, including viridis and plasma. | |
""" | |
@classmethod | |
def white_red(cls) -> Colormap: | |
"""A colormap from pure white to pure red.""" | |
cmap = LinearSegmentedColormap.from_list('white_red', ['#ffffff', '#ff0000']) | |
cmap.set_bad(color='#333333') | |
return cmap | |
@classmethod | |
def white_blue(cls) -> Colormap: | |
"""A colormap from pure white to pure blue.""" | |
cmap = LinearSegmentedColormap.from_list('white_blue', ['#ffffff', '#0000ff']) | |
cmap.set_bad(color='#333333') | |
return cmap | |
@classmethod | |
def blue_white(cls) -> Colormap: | |
"""A colormap from pure white to pure blue.""" | |
cmap = LinearSegmentedColormap.from_list('blue_white', ['#0000ff', '#ffffff']) | |
cmap.set_bad(color='#333333') | |
return cmap | |
@classmethod | |
def white_black(cls) -> Colormap: | |
"""A colormap from pure white to pure black.""" | |
cmap = LinearSegmentedColormap.from_list('white_black', ['#ffffff', '#000000']) | |
cmap.set_bad(color='#dd0000') | |
return cmap | |
@classmethod | |
def blue_white_red(cls) -> Colormap: | |
"""A colormap from pure blue to pure red.""" | |
cmap = LinearSegmentedColormap.from_list('blue_white_red', ['#0000ff', '#ffffff', '#ff0000']) | |
cmap.set_bad(color='#aaaaaa') | |
return cmap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment