Skip to content

Instantly share code, notes, and snippets.

@dmyersturnbull
Created May 5, 2020 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dmyersturnbull/c87166fe65bd9012b488cb095feef365 to your computer and use it in GitHub Desktop.
Save dmyersturnbull/c87166fe65bd9012b488cb095feef365 to your computer and use it in GitHub Desktop.
Nice extra colormaps for matplotlib.
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