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” diverging_hcl color palette and the “Purple-Orange” sequential_hcl color palette in the top row, and the “Set 2” 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 plut such a data set. The qualitative_hcl color map has iso-chroma (color intensity) and iso-luminance (lightness) and only varies in hue (the color itself). Such palettes are made for classification tasks and not to display a data set as shown in the demo plot. The gist_ncar palette should also not be used due to the immense discontinuity across the palette. More information about effective color palettes can be found on this page.

# Example of three HCL-basec cmap palettes and one from the
# 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"),

Color Vision Deficiency

The CVD toolbox of the colorspace package also allowes 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")))