However, one little problem still eats at my soul every day I use Python, specifically Matplotlib: the colors in figures are usually terrible!
My absolute favorite color map (at least for now) is cubehelix. I have written about this color map before:
CUBEHELIX, or How I Learn to Love Black & White Printers,
I also wrote the version for IDL used in the Coyote Library, and helped bring a version to the Tableau community last year.
A real cubehelix version for PythonMatplotlib already has the default cubehelix colormap built in, as well as several excellent colormaps that properly desaturate. What makes the cubehelix algorithm so powerful is that it defines a family of colormaps that all desaturate properly. This is what is missing currently in Matplotlib.
The Python community has a strong "put up or shut up" attitude that I love, so I spent a few hours translating my IDL implementation of cubehelix in to Python!
The code is available on github.
Try it out, it's dead simple to use!
import numpy as np
import matplotlib.pyplot as pltimport cubehelix
# set up some simple data to plot
x = np.random.randn(10000)
y = np.random.randn(10000)
# create the default "cubehelix" colormap
cx1 = cubehelix.cmap()
# Reverse of the default "cubehelix" colormap
# I think this is more appropriate for density maps,
# as intensity corresponds with density.
cx2 = cubehelix.cmap(reverse=True)
# My favorite flavor of "cubehelix",
# mostly blue with a small hue change
cx3 = cubehelix.cmap(reverse=True, start=0.3, rot=-0.5)
# Another good version, mostly using red/purples
cx4 = cubehelix.cmap(reverse=True, start=0., rot=0.5)
Apparently I've just reinvented the cubehelix wheel! I can live with that
@treycausey This actually already exists in matplotlib, but the custom creation of a cubehelix map is weirdly hidden at mpl._cm.cubehelix
— Michael Waskom (@michaelwaskom) April 16, 2014
The creator of D3, Mike Bostock, has made a version available for that language as well. So that's it, people. No more excuses to not use this awesome color scheme! (GitHub README)