0.11.2
  • Gallery
  • Tutorial
  • API
  • Site
      • Introduction
      • Release notes
      • Installing
      • Example gallery
      • Tutorial
      • API reference
      • Citing
      • Archive
  • Page
      • seaborn.mpl_palette

seaborn.mpl_palette¶

seaborn.mpl_palette(name, n_colors=6, as_cmap=False)¶

Return discrete colors from a matplotlib palette.

Note that this handles the qualitative colorbrewer palettes properly, although if you ask for more colors than a particular qualitative palette can provide you will get fewer than you are expecting. In contrast, asking for qualitative color brewer palettes using color_palette() will return the expected number of colors, but they will cycle.

If you are using the IPython notebook, you can also use the function choose_colorbrewer_palette() to interactively select palettes.

Parameters
namestring

Name of the palette. This should be a named matplotlib colormap.

n_colorsint

Number of discrete colors in the palette.

Returns
list of RGB tuples or matplotlib.colors.Colormap

Examples

Create a qualitative colorbrewer palette with 8 colors:

>>> import seaborn as sns; sns.set_theme()
>>> sns.palplot(sns.mpl_palette("Set2", 8))
../_images/seaborn-mpl_palette-1.png

Create a sequential colorbrewer palette:

>>> sns.palplot(sns.mpl_palette("Blues"))
../_images/seaborn-mpl_palette-2.png

Create a diverging palette:

>>> sns.palplot(sns.mpl_palette("seismic", 8))
../_images/seaborn-mpl_palette-3.png

Create a “dark” sequential palette:

>>> sns.palplot(sns.mpl_palette("GnBu_d"))
../_images/seaborn-mpl_palette-4.png

Back to top

© Copyright 2012-2021, Michael Waskom. Created using Sphinx 3.3.1.