Cubehelix was designed by D.A. Green to provide a color mapping that would degrade gracefully to grayscale without losing information. This quality makes Cubehelix very useful for continuous colour scales in scientific visualizations that might be printed in grayscale at some point. James Davenport popularized Cubehelix among matplotlib
users, and now this iteration brings Cubehelix to Palettable's beautiful API for managing color maps.
In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
The Cubehelix functionality is contained within the palettable.cubehelix
name space, and shares the same API as palettable.tableau
, palettable.brewer.sequential
, palettable.qualitative
, palettable.diverging
, and palettable.wesandersen
, for instance.
In [2]:
from palettable import cubehelix
In [3]:
cube = cubehelix.Cubehelix.make(n=5, start_hue=240., end_hue=-300.,min_sat=1., max_sat=2.5,
min_light=0.3, max_light=0.8, gamma=.9)
cube.show_as_blocks() # requires ipythonblocks
The Cubehelix docstring provides some guidance on how to build custom Cubehelix maps.
In [4]:
print(cubehelix.Cubehelix.make.__doc__)
Of course, you can also use a number of pre-made color maps. The pre-made cubehelix maps have 16 computed colors. Since matplotlib's color maps are linearly interpolated, these work great as continuous color maps.
Like the other color maps in Palettable, the cubehelix maps are available from the palettable.cubehelix
namespace. Here is a listing of color map names:
In [5]:
cubehelix.print_maps()
And examples:
In [6]:
cubehelix.classic_16.show_continuous_image()
In [7]:
cubehelix.perceptual_rainbow_16.show_continuous_image()
In [8]:
cubehelix.purple_16.show_continuous_image()
In [9]:
cubehelix.jim_special_16.show_continuous_image()
In [10]:
cubehelix.red_16.show_continuous_image()
In [11]:
cubehelix.cubehelix1_16.show_continuous_image()
In [12]:
cubehelix.cubehelix2_16.show_continuous_image()
In [13]:
cubehelix.cubehelix3_16.show_continuous_image()
Of course, you can can reverse any color map by appending _r
to the map's name.
In [14]:
cubehelix.cubehelix3_16_r.show_continuous_image()