<divid="unreleased-message"> You are reading an old version of the documentation (v3.3.2). For the latest version see <ahref="https://matplotlib.org/stable/api/colors_api.html">https://matplotlib.org/stable/api/colors_api.html</a></div>
<h1><codeclass="docutils literal notranslate"><spanclass="pre">matplotlib.colors</span></code><aclass="headerlink" href="#matplotlib-colors" title="Permalink to this headline">¶</a></h1>
<p>The Color <aclass="reference internal" href="../tutorials/index.html#tutorials-colors"><spanclass="std std-ref">tutorials</span></a> and <aclass="reference internal" href="../gallery/index.html#color-examples"><spanclass="std std-ref">examples</span></a> demonstrate how to set colors and colormaps.</p>
<spanclass="target" id="module-matplotlib.colors"></span><p>A module for converting numbers or color arguments to <em>RGB</em> or <em>RGBA</em>.</p>
<p><em>RGB</em> and <em>RGBA</em> are sequences of, respectively, 3 or 4 floats in the
range 0-1.</p>
<p>This module includes functions and classes for color specification conversions,
and for mapping numbers to colors in a 1-D array of colors called a colormap.</p>
<p>Mapping data onto colors using a colormap typically involves two steps: a data
array is first mapped onto the range 0-1 using a subclass of <aclass="reference internal" href="_as_gen/matplotlib.colors.Normalize.html#matplotlib.colors.Normalize" title="matplotlib.colors.Normalize"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Normalize</span></code></a>,
then this number is mapped to a color using a subclass of <aclass="reference internal" href="_as_gen/matplotlib.colors.Colormap.html#matplotlib.colors.Colormap" title="matplotlib.colors.Colormap"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Colormap</span></code></a>. Two
piecewise-linear interpolation to define colormaps, and <aclass="reference internal" href="_as_gen/matplotlib.colors.ListedColormap.html#matplotlib.colors.ListedColormap" title="matplotlib.colors.ListedColormap"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">ListedColormap</span></code></a>, which
makes a colormap from a list of colors.</p>
<divclass="admonition seealso">
<pclass="first admonition-title">See also</p>
<p><aclass="reference internal" href="../tutorials/colors/colormap-manipulation.html"><spanclass="doc">Creating Colormaps in Matplotlib</span></a> for examples of how to
make colormaps and</p>
<p><aclass="reference internal" href="../tutorials/colors/colormaps.html"><spanclass="doc">Choosing Colormaps in Matplotlib</span></a> for a list of built-in colormaps.</p>
<p><aclass="reference internal" href="../tutorials/colors/colormapnorms.html"><spanclass="doc">Colormap Normalization</span></a> for more details about data
normalization</p>
<pclass="last">More colormaps are available at <aclass="reference external" href="https://jiffyclub.github.io/palettable/">palettable</a>.</p>
</div>
<p>The module also provides functions for checking whether an object can be
interpreted as a color (<aclass="reference internal" href="_as_gen/matplotlib.colors.is_color_like.html#matplotlib.colors.is_color_like" title="matplotlib.colors.is_color_like"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">is_color_like</span></code></a>), for converting such an object
to an RGBA tuple (<aclass="reference internal" href="_as_gen/matplotlib.colors.to_rgba.html#matplotlib.colors.to_rgba" title="matplotlib.colors.to_rgba"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">to_rgba</span></code></a>) or to an HTML-like hex string in the
"#rrggbb" format (<aclass="reference internal" href="_as_gen/matplotlib.colors.to_hex.html#matplotlib.colors.to_hex" title="matplotlib.colors.to_hex"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">to_hex</span></code></a>), and a sequence of colors to an (n, 4)
RGBA array (<aclass="reference internal" href="_as_gen/matplotlib.colors.to_rgba_array.html#matplotlib.colors.to_rgba_array" title="matplotlib.colors.to_rgba_array"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">to_rgba_array</span></code></a>). Caching is used for efficiency.</p>
<p>Matplotlib recognizes the following formats to specify a color:</p>
<ulclass="simple">
<li>an RGB or RGBA (red, green, blue, alpha) tuple of float values in closed
<li>a hex RGB or RGBA string (e.g., <codeclass="docutils literal notranslate"><spanclass="pre">'#0f0f0f'</span></code> or <codeclass="docutils literal notranslate"><spanclass="pre">'#0f0f0f80'</span></code>;
case-insensitive);</li>
<li>a shorthand hex RGB or RGBA string, equivalent to the hex RGB or RGBA
string obtained by duplicating each character, (e.g., <codeclass="docutils literal notranslate"><spanclass="pre">'#abc'</span></code>, equivalent
to <codeclass="docutils literal notranslate"><spanclass="pre">'#aabbcc'</span></code>, or <codeclass="docutils literal notranslate"><spanclass="pre">'#abcd'</span></code>, equivalent to <codeclass="docutils literal notranslate"><spanclass="pre">'#aabbccdd'</span></code>;
case-insensitive);</li>
<li>a string representation of a float value in <codeclass="docutils literal notranslate"><spanclass="pre">[0,</span><spanclass="pre">1]</span></code> inclusive for gray
<li>one of the characters <codeclass="docutils literal notranslate"><spanclass="pre">{'b',</span><spanclass="pre">'g',</span><spanclass="pre">'r',</span><spanclass="pre">'c',</span><spanclass="pre">'m',</span><spanclass="pre">'y',</span><spanclass="pre">'k',</span><spanclass="pre">'w'}</span></code>, which
are short-hand notations for shades of blue, green, red, cyan, magenta,
yellow, black, and white. Note that the colors <codeclass="docutils literal notranslate"><spanclass="pre">'g',</span><spanclass="pre">'c',</span><spanclass="pre">'m',</span><spanclass="pre">'y'</span></code> do not
coincide with the X11/CSS4 colors. Their particular shades were chosen for
better visibility of colored lines against typical backgrounds.</li>
<li>a X11/CSS4 color name (case-insensitive);</li>
<li>a name from the <aclass="reference external" href="https://xkcd.com/color/rgb/">xkcd color survey</a>, prefixed with <codeclass="docutils literal notranslate"><spanclass="pre">'xkcd:'</span></code> (e.g.,
<codeclass="docutils literal notranslate"><spanclass="pre">'xkcd:sky</span><spanclass="pre">blue'</span></code>; case insensitive);</li>
<li>one of the Tableau Colors from the 'T10' categorical palette (the default
color cycle): <codeclass="docutils literal notranslate"><spanclass="pre">{'tab:blue',</span><spanclass="pre">'tab:orange',</span><spanclass="pre">'tab:green',</span><spanclass="pre">'tab:red',</span>
<td>Dummy replacement for <aclass="reference internal" href="_as_gen/matplotlib.colors.Normalize.html#matplotlib.colors.Normalize" title="matplotlib.colors.Normalize"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Normalize</span></code></a>, for the case where we want to use indices directly in a <aclass="reference internal" href="cm_api.html#matplotlib.cm.ScalarMappable" title="matplotlib.cm.ScalarMappable"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">ScalarMappable</span></code></a>.</td>
<td>A class which, when called, linearly normalizes data into the <codeclass="docutils literal notranslate"><spanclass="pre">[0.0,</span><spanclass="pre">1.0]</span></code> interval.</td>