Colors and Style

Yellowbrick believes that visual diagnostics are more effective if visualizations are appealing. As a result, we have borrowed familiar styles from Seaborn and use the new Matplotlib 2.0 styles. We hope that these out of the box styles will make your visualizations publication ready, though of course you can customize your own look and feel by directly modifying the visualization with matplotlib.

Yellowbrick prioritizes color in its visualizations for most visualizers. There are two types of color sets that can be provided to a visualizer: a palette and a sequence. Palettes are discrete color values usually of a fixed length and are typically used for classification or clustering by showing each class, cluster or topic. Sequences are continuous color values that do not have a fixed length but rather a range and are typically used for regression or clustering, showing all possible values in the target or distances between items in clusters.

In order to make the distinction easy, most matplotlib colors (both palettes and sequences) can be referred to by name. A complete listing can be imported as follows:

import matplotlib.pyplot as plt
from yellowbrick.style.palettes import PALETTES, SEQUENCES, color_palette

Palettes and sequences can be passed to visualizers as follows:

visualizer = Visualizer(color="bold")

Refer to the API listing of each visualizer for specifications about how each color argument is handled. In the next two sections we will show every possible color palette and sequence currently available in Yellowbrick.

Color Palettes

Color palettes are discrete color lists that have a fixed length. The most common palettes are ordered as "blue", "green", "red", "maroon", "yellow", "cyan", and an optional "key". This allows you to specify these named colors or by the first character, e.g. 'bgrmyck' for matplotlib visualizations.

To change the global color palette, use the set_palette function as follows:

from yellowbrick.style import set_palette
set_palette('flatui')

Color palettes are most often used for classifiers to show the relationship between discrete class labels. They can also be used for clustering algorithms to show membership in discrete clusters.

A complete listing of the Yellowbrick color palettes can be visualized as follows:

# ['blue', 'green', 'red', 'maroon', 'yellow', 'cyan']
for palette in PALETTES.keys():
    color_palette(palette).plot()
    plt.title(palette, loc='left')
../_images/palettes_2_0.png ../_images/palettes_2_1.png ../_images/palettes_2_2.png ../_images/palettes_2_3.png ../_images/palettes_2_4.png ../_images/palettes_2_5.png ../_images/palettes_2_6.png ../_images/palettes_2_7.png ../_images/palettes_2_8.png ../_images/palettes_2_9.png ../_images/palettes_2_10.png ../_images/palettes_2_11.png ../_images/palettes_2_12.png ../_images/palettes_2_13.png ../_images/palettes_2_14.png ../_images/palettes_2_15.png ../_images/palettes_2_16.png

Color Sequences

Color sequences are continuous representations of color and are usually defined as a fixed number of steps between a minimum and maximal value. Sequences must be created with a total number of bins (or length) before plotting to ensure that values are assigned correctly. In the listing below, each sequence is shown with varying lengths to describe the range of colors in detail.

Color sequences are most often used in regressions to show the distribution in the range of target values. They can also be used in clustering and distribution analysis to show distance or histogram data.

Below is a complete listing of all the sequence names available in Yellowbrick:

for name, maps in SEQUENCES.items():
    for num, palette in maps.items():
        color_palette(palette).plot()
        plt.title("{} - {}".format(name, num), loc='left')
../_images/palettes_3_1.png ../_images/palettes_3_2.png ../_images/palettes_3_3.png ../_images/palettes_3_4.png ../_images/palettes_3_5.png ../_images/palettes_3_6.png ../_images/palettes_3_7.png ../_images/palettes_3_8.png ../_images/palettes_3_9.png ../_images/palettes_3_10.png ../_images/palettes_3_11.png ../_images/palettes_3_12.png ../_images/palettes_3_13.png ../_images/palettes_3_14.png ../_images/palettes_3_15.png ../_images/palettes_3_16.png ../_images/palettes_3_17.png ../_images/palettes_3_18.png ../_images/palettes_3_19.png ../_images/palettes_3_20.png ../_images/palettes_3_21.png ../_images/palettes_3_22.png ../_images/palettes_3_23.png ../_images/palettes_3_24.png ../_images/palettes_3_25.png ../_images/palettes_3_26.png ../_images/palettes_3_27.png ../_images/palettes_3_28.png ../_images/palettes_3_29.png ../_images/palettes_3_30.png ../_images/palettes_3_31.png ../_images/palettes_3_32.png ../_images/palettes_3_33.png ../_images/palettes_3_34.png ../_images/palettes_3_35.png ../_images/palettes_3_36.png ../_images/palettes_3_37.png ../_images/palettes_3_38.png ../_images/palettes_3_39.png ../_images/palettes_3_40.png ../_images/palettes_3_41.png ../_images/palettes_3_42.png ../_images/palettes_3_43.png ../_images/palettes_3_44.png ../_images/palettes_3_45.png ../_images/palettes_3_46.png ../_images/palettes_3_47.png ../_images/palettes_3_48.png ../_images/palettes_3_49.png ../_images/palettes_3_50.png ../_images/palettes_3_51.png ../_images/palettes_3_52.png ../_images/palettes_3_53.png ../_images/palettes_3_54.png ../_images/palettes_3_55.png ../_images/palettes_3_56.png ../_images/palettes_3_57.png ../_images/palettes_3_58.png ../_images/palettes_3_59.png ../_images/palettes_3_60.png ../_images/palettes_3_61.png ../_images/palettes_3_62.png ../_images/palettes_3_63.png ../_images/palettes_3_64.png ../_images/palettes_3_65.png ../_images/palettes_3_66.png ../_images/palettes_3_67.png ../_images/palettes_3_68.png ../_images/palettes_3_69.png ../_images/palettes_3_70.png ../_images/palettes_3_71.png ../_images/palettes_3_72.png ../_images/palettes_3_73.png ../_images/palettes_3_74.png ../_images/palettes_3_75.png ../_images/palettes_3_76.png ../_images/palettes_3_77.png ../_images/palettes_3_78.png ../_images/palettes_3_79.png ../_images/palettes_3_80.png ../_images/palettes_3_81.png ../_images/palettes_3_82.png ../_images/palettes_3_83.png ../_images/palettes_3_84.png ../_images/palettes_3_85.png ../_images/palettes_3_86.png ../_images/palettes_3_87.png ../_images/palettes_3_88.png ../_images/palettes_3_89.png ../_images/palettes_3_90.png ../_images/palettes_3_91.png ../_images/palettes_3_92.png ../_images/palettes_3_93.png ../_images/palettes_3_94.png ../_images/palettes_3_95.png ../_images/palettes_3_96.png ../_images/palettes_3_97.png ../_images/palettes_3_98.png ../_images/palettes_3_99.png ../_images/palettes_3_100.png ../_images/palettes_3_101.png ../_images/palettes_3_102.png ../_images/palettes_3_103.png ../_images/palettes_3_104.png ../_images/palettes_3_105.png ../_images/palettes_3_106.png ../_images/palettes_3_107.png ../_images/palettes_3_108.png ../_images/palettes_3_109.png ../_images/palettes_3_110.png ../_images/palettes_3_111.png ../_images/palettes_3_112.png ../_images/palettes_3_113.png ../_images/palettes_3_114.png ../_images/palettes_3_115.png ../_images/palettes_3_116.png ../_images/palettes_3_117.png ../_images/palettes_3_118.png ../_images/palettes_3_119.png ../_images/palettes_3_120.png ../_images/palettes_3_121.png ../_images/palettes_3_122.png ../_images/palettes_3_123.png ../_images/palettes_3_124.png ../_images/palettes_3_125.png ../_images/palettes_3_126.png ../_images/palettes_3_127.png ../_images/palettes_3_128.png ../_images/palettes_3_129.png ../_images/palettes_3_130.png ../_images/palettes_3_131.png ../_images/palettes_3_132.png ../_images/palettes_3_133.png ../_images/palettes_3_134.png ../_images/palettes_3_135.png ../_images/palettes_3_136.png ../_images/palettes_3_137.png ../_images/palettes_3_138.png ../_images/palettes_3_139.png ../_images/palettes_3_140.png ../_images/palettes_3_141.png ../_images/palettes_3_142.png ../_images/palettes_3_143.png ../_images/palettes_3_144.png ../_images/palettes_3_145.png ../_images/palettes_3_146.png ../_images/palettes_3_147.png ../_images/palettes_3_148.png ../_images/palettes_3_149.png ../_images/palettes_3_150.png ../_images/palettes_3_151.png ../_images/palettes_3_152.png ../_images/palettes_3_153.png ../_images/palettes_3_154.png ../_images/palettes_3_155.png ../_images/palettes_3_156.png ../_images/palettes_3_157.png ../_images/palettes_3_158.png ../_images/palettes_3_159.png ../_images/palettes_3_160.png ../_images/palettes_3_161.png ../_images/palettes_3_162.png ../_images/palettes_3_163.png ../_images/palettes_3_164.png ../_images/palettes_3_165.png ../_images/palettes_3_166.png ../_images/palettes_3_167.png ../_images/palettes_3_168.png ../_images/palettes_3_169.png ../_images/palettes_3_170.png ../_images/palettes_3_171.png ../_images/palettes_3_172.png ../_images/palettes_3_173.png ../_images/palettes_3_174.png ../_images/palettes_3_175.png ../_images/palettes_3_176.png ../_images/palettes_3_177.png ../_images/palettes_3_178.png ../_images/palettes_3_179.png ../_images/palettes_3_180.png ../_images/palettes_3_181.png ../_images/palettes_3_182.png ../_images/palettes_3_183.png ../_images/palettes_3_184.png ../_images/palettes_3_185.png ../_images/palettes_3_186.png ../_images/palettes_3_187.png ../_images/palettes_3_188.png ../_images/palettes_3_189.png ../_images/palettes_3_190.png ../_images/palettes_3_191.png ../_images/palettes_3_192.png ../_images/palettes_3_193.png ../_images/palettes_3_194.png ../_images/palettes_3_195.png ../_images/palettes_3_196.png ../_images/palettes_3_197.png ../_images/palettes_3_198.png ../_images/palettes_3_199.png ../_images/palettes_3_200.png ../_images/palettes_3_201.png ../_images/palettes_3_202.png ../_images/palettes_3_203.png ../_images/palettes_3_204.png ../_images/palettes_3_205.png ../_images/palettes_3_206.png ../_images/palettes_3_207.png ../_images/palettes_3_208.png

API Reference

yellowbrick.style.colors module

Colors and color helpers brought in from an alternate library. See https://bl.ocks.org/mbostock/5577023

class yellowbrick.style.colors.ColorMap(colors='flatui', shuffle=False)[源代码]

基类:object

A helper for mapping categorical values to colors on demand.

colors
yellowbrick.style.colors.get_color_cycle()[源代码]

Returns the current color cycle from matplotlib.

yellowbrick.style.colors.resolve_colors(n_colors=None, colormap=None, colors=None)[源代码]

Generates a list of colors based on common color arguments, for example the name of a colormap or palette or another iterable of colors. The list is then truncated (or multiplied) to the specific number of requested colors.

Parameters:
n_colors : int, default: None

Specify the length of the list of returned colors, which will either truncate or multiple the colors available. If None the length of the colors will not be modified.

colormap : str, default: None

The name of the matplotlib color map with which to generate colors.

colors : iterable, default: None

A collection of colors to use specifically with the plot.

Returns:
colors : list

A list of colors that can be used in matplotlib plots.

Notes

This function was originally based on a similar function in the pandas plotting library that has been removed in the new version of the library.

yellowbrick.style.palettes module

Implements the variety of colors that yellowbrick allows access to by name. This code was originally based on Seaborn's rcmody.py but has since been cleaned up to be Yellowbrick-specific and to dereference tools we don't use. Note that these functions alter the matplotlib rc dictionary on the fly.

yellowbrick.style.palettes.color_palette(palette=None, n_colors=None)[源代码]

Return a color palette object with color definition and handling.

Calling this function with palette=None will return the current matplotlib color cycle.

This function can also be used in a with statement to temporarily set the color cycle for a plot or set of plots.

Parameters:
palette : None or str or sequence

Name of a palette or None to return the current palette. If a sequence the input colors are used but possibly cycled.

Available palette names from yellowbrick.colors.palettes are:

  • accent
  • dark
  • paired
  • pastel
  • bold
  • muted
  • colorblind
  • sns_colorblind
  • sns_deep
  • sns_muted
  • sns_pastel
  • sns_bright
  • sns_dark
  • flatui
  • neural_paint
n_colors : None or int

Number of colors in the palette. If None, the default will depend on how palette is specified. Named palettes default to 6 colors which allow the use of the names "bgrmyck", though others do have more or less colors; therefore reducing the size of the list can only be done by specifying this parameter. Asking for more colors than exist in the palette will cause it to cycle.

Returns:
list(tuple)

Returns a ColorPalette object, which behaves like a list, but can be used as a context manager and possesses functions to convert colors.

.. seealso::
set_palette()

Set the default color cycle for all plots.

set_color_codes()

Reassign color codes like "b", "g", etc. to colors from one of the yellowbrick palettes.

colors.resolve_colors()

Resolve a color map or listed sequence of colors.

yellowbrick.style.palettes.set_color_codes(palette='accent')[源代码]

Change how matplotlib color shorthands are interpreted.

Calling this will change how shorthand codes like "b" or "g" are interpreted by matplotlib in subsequent plots.

Parameters:
palette : str

Named yellowbrick palette to use as the source of colors.

参见

set_palette
Color codes can also be set through the function that sets the matplotlib color cycle.

yellowbrick.style.rcmod module

Modifies the matplotlib rcParams in order to make yellowbrick more appealing. This has been modified from Seaborn's rcmod.py: github.com/mwaskom/seaborn in order to alter the matplotlib rc dictionary on the fly.

NOTE: matplotlib 2.0 styles mean we can simply convert this to a stylesheet!

yellowbrick.style.rcmod.set_aesthetic(palette='yellowbrick', font='sans-serif', font_scale=1, color_codes=True, rc=None)[源代码]

Set aesthetic parameters in one step.

Each set of parameters can be set directly or temporarily, see the referenced functions below for more information.

Parameters:
palette : string or sequence

Color palette, see color_palette()

font : string

Font family, see matplotlib font manager.

font_scale : float, optional

Separate scaling factor to independently scale the size of the font elements.

color_codes : bool

If True and palette is a yellowbrick palette, remap the shorthand color codes (e.g. "b", "g", "r", etc.) to the colors from this palette.

rc : dict or None

Dictionary of rc parameter mappings to override the above.

yellowbrick.style.rcmod.set_style(style=None, rc=None)[源代码]

Set the aesthetic style of the plots.

This affects things like the color of the axes, whether a grid is enabled by default, and other aesthetic elements.

Parameters:
style : dict, None, or one of {darkgrid, whitegrid, dark, white, ticks}

A dictionary of parameters or the name of a preconfigured set.

rc : dict, optional

Parameter mappings to override the values in the preset seaborn style dictionaries. This only updates parameters that are considered part of the style definition.

yellowbrick.style.rcmod.set_palette(palette, n_colors=None, color_codes=False)[源代码]

Set the matplotlib color cycle using a seaborn palette.

Parameters:
palette : yellowbrick color palette | seaborn color palette (with sns_ prepended)

Palette definition. Should be something that color_palette() can process.

n_colors : int

Number of colors in the cycle. The default number of colors will depend on the format of palette, see the color_palette() documentation for more information.

color_codes : bool

If True and palette is a seaborn palette, remap the shorthand color codes (e.g. "b", "g", "r", etc.) to the colors from this palette.

yellowbrick.style.rcmod.reset_defaults()[源代码]

Restore all RC params to default settings.

yellowbrick.style.rcmod.reset_orig()[源代码]

Restore all RC params to original settings (respects custom rc).