Matolotlib cmaps

For demonstration the 3D surface demo is used to demonstrate the colorspace cmap functionality. The code for the demo can be a the end of this page.

HCL Color Palettes

# Demo plot based on the default diverging_hcl color palette
from colorspace import diverging_hcl 
pal = diverging_hcl()
demo(pal.cmap(100, name = "Color Map with 100 Colors"),
     pal.cmap(7,   name = "Color Map with 7 Colors"))

All palettes.hclpalette objects provide a method called palettes.hclpalette.cmap() method which returns a matplotlib color map with n colors (default 51).

The example below shows the demo with the “Green-Orange” palettes.diverging_hcl color palette and the “Purple-Orange” palettes.sequential_hcl color palette in the top row, and the “Set 2” palettes.qualitative_hcl and a matplotlib default color map called gist_ncar in the bottom row.

Please note: that none of the two shown in the bottom row should be used to illustrate such a data set. The palettes.qualitative_hcl color map has iso-chroma (constant color intensity) and iso-luminance (constant lightness) and only varies in the hue dimension (the color itself). Such palettes are made for classification tasks and not to display a data set as shown in the demo. The gist_ncar palette should also not be used due to the immense discontinuity across the palette (I’ve chosen this as one of the worst examples among the matplotlib color maps). More information about effective color palettes can be found on this page.

# Example of three HCL-basec cmap palettes and one from the
# matplotlib.cm module (gist_ncar; one which should not be used).
from colorspace import diverging_hcl, sequential_hcl, qualitative_hcl
from matplotlib import cm
div  = diverging_hcl("Green-Orange")
seq  = sequential_hcl("Purple-Orange", rev = True)
qual = qualitative_hcl("Set 2")
demo(div.cmap(name = "Diverging Color Map"),
     seq.cmap(name = "Sequential Color Map"),
     qual.cmap(name = "Qualitative Color Map"),
     cm.gist_ncar)

Color Vision Deficiency

The color vision deficiency (CVD) toolbox of the colorspace package also allows to simulate color vision deficiencies on matplotlib.colors.LinearSegmentedColormap color maps.

# Demo plot based on the default diverging_hcl color palette
# with 51 (default) distinct colors.
# Normal color vision, a desaturated version, plus simulated
# deuteranope and protanope color vision.
from colorspace import diverging_hcl, desaturate, deutan, protan
pal = diverging_hcl()
demo(pal.cmap(name = "Normal Color Vision"),
     desaturate(pal.cmap(name = "Desaturated")),
     deutan(pal.cmap(name = "Deuteranope Color Vision")),
     protan(pal.cmap(name = "Protanope Color Vision")))