In [1]:
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline

Choosing color palettes and color maps

In the Jupyter notebook, seaborn provides useful interactive tools to choose and customize a color palette. Note that if your function requires a colormap instead, just give the argument as_camp=True.

Color Brewer palettes

For description of these palettes, see ColorBrewer

Sequential palettes are appropriate for data that goes from low to high.

In [2]:
sns.choose_colorbrewer_palette('sequential')
Out[2]:
[(0.95755478915046244, 0.95755478915046244, 0.95755478915046244),
 (0.90120723387774304, 0.90120723387774304, 0.90120723387774304),
 (0.83289505032932054, 0.83289505032932054, 0.83289505032932054),
 (0.75021916137022127, 0.75021916137022127, 0.75021916137022127),
 (0.64341409276513495, 0.64341409276513495, 0.64341409276513495),
 (0.53871589525073182, 0.53871589525073182, 0.53871589525073182),
 (0.44032295626752516, 0.44032295626752516, 0.44032295626752516),
 (0.34288351570858677, 0.34288351570858677, 0.34288351570858677),
 (0.22329873945198808, 0.22329873945198808, 0.22329873945198808),
 (0.1046981975144031, 0.1046981975144031, 0.1046981975144031)]
_images/ChousingColorPlalettes_4_1.png
In [3]:
exercise = sns.load_dataset("exercise", index_col = 0)
In [4]:
sns.barplot(x = 'time', y = 'pulse', hue = 'diet', data = exercise,
            palette = 'RdBu_r')
pass
_images/ChousingColorPlalettes_6_0.png

Saving the palette in a varibele for later use in a plotting fucntion.

All the choose palette functions return palette information that cna be used in a seaborn plotting function. They can also return a colormap for functions that accept a cmap argument by giving the argument as_camp=True.

In [5]:
p = sns.choose_colorbrewer_palette('sequential')
_images/ChousingColorPlalettes_8_0.png
In [6]:
sns.barplot(x = 'time', y = 'pulse', hue = 'diet', data = exercise,
            palette = p)
pass
_images/ChousingColorPlalettes_9_0.png

Divergent palettes are appropriate when there is a “center” and both extremes are interesting and should be differentiated.

In [7]:
sns.choose_colorbrewer_palette('divergent')
Out[7]:
[(0.69227222075649331, 0.092272204803485525, 0.16770473370949396),
 (0.83921569585800171, 0.37647059559822083, 0.30196079611778259),
 (0.95455594273174504, 0.64175319262579378, 0.5057285948126925),
 (0.99215686321258534, 0.85882353782653809, 0.78039216995239269),
 (0.96570549992954036, 0.96724336988785686, 0.96808919836493101),
 (0.81960785388946544, 0.89803922176361084, 0.94117647409439076),
 (0.56647445816619735, 0.76870435826918648, 0.8685121185639324),
 (0.26274511218070995, 0.57647061347961415, 0.76470589637756337),
 (0.12725875369620088, 0.3958477567808299, 0.66874281039424976)]
_images/ChousingColorPlalettes_11_1.png

Qualitative palettes are custom configurations useful for unordered categorical data.

In [8]:
sns.choose_colorbrewer_palette('qualitative')
Out[8]:
[(0.89411765336990356, 0.10196078568696976, 0.1098039224743836),
 (0.21602460800432688, 0.49487120380588578, 0.71987698697576341),
 (0.30426760128900115, 0.68329106055054012, 0.29293349969620797),
 (0.60083047361934894, 0.30814303335021531, 0.63169552298153153),
 (1.0, 0.50591311045721454, 0.0031372549487094226),
 (0.99315647868549106, 0.98700499826786559, 0.19915417450315831),
 (0.65845446095747096, 0.34122261685483596, 0.17079585352364723),
 (0.95850826852461857, 0.50846600392285535, 0.7449288887136124),
 (0.60000002384185791, 0.60000002384185791, 0.60000002384185791)]
_images/ChousingColorPlalettes_13_1.png

Other palettes

In [9]:
sns.choose_cubehelix_palette()
Out[9]:
[[0.9312692223325372, 0.8201921796082118, 0.7971480974663592],
 [0.8888663743660877, 0.7106793139856472, 0.7158661451411206],
 [0.8314793143949643, 0.5987041921652179, 0.6530062709235388],
 [0.7588951019517731, 0.49817117746394224, 0.6058723814510268],
 [0.6672565752652589, 0.40671838146419587, 0.5620016466433286],
 [0.5529215689527474, 0.3217924564263954, 0.5093718054521851],
 [0.43082755198027817, 0.24984535814964698, 0.44393960899639856],
 [0.29794615023641036, 0.18145907625614888, 0.3531778140503475],
 [0.1750865648952205, 0.11840023306916837, 0.24215989137836502]]
_images/ChousingColorPlalettes_15_1.png
In [10]:
sns.choose_diverging_palette()
Out[10]:
[array([ 0.25199714,  0.49873371,  0.57516028,  1.        ]),
 array([ 0.43026136,  0.62000665,  0.67878019,  1.        ]),
 array([ 0.60852558,  0.74127959,  0.7824001 ,  1.        ]),
 array([ 0.7867898 ,  0.86255253,  0.88602001,  1.        ]),
 array([ 0.95,  0.95,  0.95,  1.  ]),
 array([ 0.95457726,  0.76653099,  0.78032569,  1.        ]),
 array([ 0.91971827,  0.58735877,  0.61174   ,  1.        ]),
 array([ 0.88485928,  0.40818655,  0.44315432,  1.        ]),
 array([ 0.85104086,  0.23436275,  0.27960104,  1.        ])]
_images/ChousingColorPlalettes_16_1.png
In [11]:
sns.choose_dark_palette()
Out[11]:
[array([ 0.13333333,  0.13333333,  0.13333333,  1.        ]),
 array([ 0.15505626,  0.17201694,  0.16963164,  1.        ]),
 array([ 0.17677918,  0.21070054,  0.20592994,  1.        ]),
 array([ 0.19927793,  0.2507657 ,  0.24352462,  1.        ]),
 array([ 0.22100085,  0.2894493 ,  0.27982292,  1.        ]),
 array([ 0.2434996 ,  0.32951446,  0.31741759,  1.        ]),
 array([ 0.26522252,  0.36819806,  0.3537159 ,  1.        ]),
 array([ 0.28772127,  0.40826322,  0.39131057,  1.        ]),
 array([ 0.30944419,  0.44694683,  0.42760888,  1.        ]),
 array([ 0.33116712,  0.48563043,  0.46390718,  1.        ])]
_images/ChousingColorPlalettes_17_1.png
In [12]:
sns.choose_light_palette()
Out[12]:
[array([ 0.94054458,  0.95945542,  0.95679586,  1.        ]),
 array([ 0.87363254,  0.90742758,  0.90267475,  1.        ]),
 array([ 0.80672051,  0.85539974,  0.84855364,  1.        ]),
 array([ 0.73741876,  0.80151376,  0.79249963,  1.        ]),
 array([ 0.67050672,  0.74948591,  0.73837852,  1.        ]),
 array([ 0.60120497,  0.69559993,  0.68232452,  1.        ]),
 array([ 0.53429294,  0.64357209,  0.62820341,  1.        ]),
 array([ 0.46499119,  0.58968611,  0.5721494 ,  1.        ]),
 array([ 0.39807915,  0.53765827,  0.51802829,  1.        ]),
 array([ 0.33116712,  0.48563043,  0.46390718,  1.        ])]
_images/ChousingColorPlalettes_18_1.png