plot_get_clist
- plot_get_clist(n_colors=3, kind='categorical', cmap=None, facecolor_dark=False)[source]
Get a list of
n_colorscolors for a categorical, continuous, or diverging palette.This is the single entry point for quickly obtaining a color list of any size and type. Following Matplotlib’s colormap taxonomy,
kindselects the palette family and the optionalcmapselects the concrete palette within it:categorical(qualitative): maximally distinct colors for discrete classes. Hand-curated for 2 to 9 colors, the'husl'palette for 10 to 20.continuous(sequential or qualitative):n_colorssampled from any named palette. An ordered map such as'viridis'yields a perceptual ramp (encodes magnitude); a qualitative map such as'husl'yields distinct hues.diverging: two hues from a neutral center, for signed/centered data. The house'CPP'/'SHAP'maps or any Matplotlib diverging map (e.g.'coolwarm').
For
categorical/continuousthe colors are produced viaseaborn.color_palette(), so any Matplotlib colormap name plus seaborn’s'husl'/'hls'generators are accepted ascmap; see the seaborn palette documentation for the full set. For a full pre-sized diverging colormap (101 points by default) useplot_get_cmap()instead.Added in version 0.1.2.
- Parameters:
n_colors (int, default=3) – Number of colors. Must be at least 2 (
categorical, at most 20) or 3 (continuous/diverging).kind ({'categorical', 'continuous', 'diverging'}, default='categorical') – Palette family to draw colors from.
cmap (str, optional) – Name of the concrete palette. If
None, defaults to the curated list (categorical),'husl'(continuous), or'CPP'(diverging). Accepts any Matplotlib colormap name and seaborn’s'husl'/'hls';'CPP'and'SHAP'are valid only forkind='diverging'.facecolor_dark (bool, default=False) – Whether the central color of a diverging map is black (if
True) or white (ifFalse). Only applies tokind='diverging'; ignored otherwise.
- Returns:
colors – List of
n_colorscolors. Matplotlib color-name strings for the curated categorical list, otherwise RGB tuples.- Return type:
See also
plot_get_cmap()for the pre-sized divergingCPP/SHAPcolormaps.plot_get_cdict()for the named category-to-color dictionaries.The example notebooks in Plotting Prelude.
seaborn.color_palette()function to generate a color palette in seaborn.
Examples
You can retrieve a list of n colors by using the
n_colorsparameter:import matplotlib.pyplot as plt import seaborn as sns import aaanalysis as aa colors = aa.plot_get_clist(n_colors=2) sns.palplot(colors) plt.show()
We assembled 8 different color lists for 2 to 9 colors:
for n in range(3, 9): colors = aa.plot_get_clist(n_colors=n) sns.palplot(colors) plt.show()
For more than 9 colors, we provide the ‘husl’ default color palette of the :func:
seaborn.color_palettefunction:for n in [10, 15, 20]: colors = aa.plot_get_clist(n_colors=n) sns.palplot(colors) plt.show()
Use the
kindparameter to switch the palette family (following Matplotlib’s colormap taxonomy) andcmapto pick a concrete palette within it. Forcategoricalandcontinuouspalettes the colors come from :func:seaborn.color_palette, so any Matplotlib colormap name plus ‘husl’/‘hls’ is accepted; see the seaborn palette documentation for the full set.For
kind='categorical'you can pass any qualitativecmap(e.g. ‘Set2’, ‘tab20’, ‘hls’) instead of the curated default:for cmap in ["Set2", "tab20", "hls"]: colors = aa.plot_get_clist(n_colors=8, kind="categorical", cmap=cmap) sns.palplot(colors) plt.show()
For
kind='continuous', an ordered colormap such as ‘viridis’ gives a perceptual ramp (encoding magnitude), while a qualitative one such as ‘husl’ (the default) gives distinct hues:for cmap in ["viridis", "magma", "husl"]: colors = aa.plot_get_clist(n_colors=12, kind="continuous", cmap=cmap) sns.palplot(colors) plt.show()
For
kind='diverging', use the house ‘CPP’/‘SHAP’ maps or any Matplotlib diverging map (e.g. ‘coolwarm’):for cmap in ["CPP", "SHAP", "coolwarm"]: colors = aa.plot_get_clist(n_colors=11, kind="diverging", cmap=cmap) sns.palplot(colors) plt.show()
The
facecolor_darkparameter switches the central color of a diverging map between white (default) and black:colors = aa.plot_get_clist(n_colors=11, kind="diverging", cmap="CPP", facecolor_dark=True) sns.palplot(colors) plt.show()