<divid="unreleased-message"> You are reading an old version of the documentation (v2.1.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>
<spanid="matplotlib-colors"></span><h2><aclass="reference internal" href="#module-matplotlib.colors" title="matplotlib.colors"><codeclass="xref py py-mod docutils literal"><spanclass="pre">matplotlib.colors</span></code></a><aclass="headerlink" href="#module-matplotlib.colors" title="Permalink to this headline">¶</a></h2>
<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. Colormapping typically involves two steps: a data array is first
mapped onto the range 0-1 using an instance of <aclass="reference internal" href="_as_gen/matplotlib.colors.Normalize.html#matplotlib.colors.Normalize" title="matplotlib.colors.Normalize"><codeclass="xref py py-class docutils literal"><spanclass="pre">Normalize</span></code></a> or of a
subclass; then this number in the 0-1 range is mapped to a color using an
instance of a subclass of <aclass="reference internal" href="_as_gen/matplotlib.colors.Colormap.html#matplotlib.colors.Colormap" title="matplotlib.colors.Colormap"><codeclass="xref py py-class docutils literal"><spanclass="pre">Colormap</span></code></a>. Two are provided here:
<aclass="reference internal" href="_as_gen/matplotlib.colors.LinearSegmentedColormap.html#matplotlib.colors.LinearSegmentedColormap" title="matplotlib.colors.LinearSegmentedColormap"><codeclass="xref py py-class docutils literal"><spanclass="pre">LinearSegmentedColormap</span></code></a>, which is used to generate all the built-in
colormap instances, but is also useful for making custom colormaps, and
<aclass="reference internal" href="_as_gen/matplotlib.colors.ListedColormap.html#matplotlib.colors.ListedColormap" title="matplotlib.colors.ListedColormap"><codeclass="xref py py-class docutils literal"><spanclass="pre">ListedColormap</span></code></a>, which is used for generating a custom colormap from a
list of color specifications.</p>
<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-func docutils literal"><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-func docutils literal"><spanclass="pre">to_rgba()</span></code></a>) or to an HTML-like hex string in the
<codeclass="xref py py-obj docutils literal"><spanclass="pre">#rrggbb</span></code> 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-func docutils literal"><spanclass="pre">to_hex()</span></code></a>), and a sequence of colors to an <codeclass="xref py py-obj docutils literal"><spanclass="pre">(n,</span><spanclass="pre">4)</span></code>
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-func docutils literal"><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 tuple of float values in <codeclass="docutils literal"><spanclass="pre">[0,</span><spanclass="pre">1]</span></code> (e.g., <codeclass="docutils literal"><spanclass="pre">(0.1,</span><spanclass="pre">0.2,</span><spanclass="pre">0.5)</span></code>
or <codeclass="docutils literal"><spanclass="pre">(0.1,</span><spanclass="pre">0.2,</span><spanclass="pre">0.5,</span><spanclass="pre">0.3)</span></code>);</li>
<li>a hex RGB or RGBA string (e.g., <codeclass="docutils literal"><spanclass="pre">'#0F0F0F'</span></code> or <codeclass="docutils literal"><spanclass="pre">'#0F0F0F0F'</span></code>);</li>
<li>a string representation of a float value in <codeclass="docutils literal"><spanclass="pre">[0,</span><spanclass="pre">1]</span></code> inclusive for gray
<li>one of <codeclass="docutils literal"><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>;</li>
<li>a X11/CSS4 color name;</li>
<li>a name from the <aclass="reference external" href="https://xkcd.com/color/rgb/">xkcd color survey</a>;
prefixed with <codeclass="docutils literal"><spanclass="pre">'xkcd:'</span></code> (e.g., <codeclass="docutils literal"><spanclass="pre">'xkcd:sky</span><spanclass="pre">blue'</span></code>);</li>
<li>one of <codeclass="docutils literal"><spanclass="pre">{'tab:blue',</span><spanclass="pre">'tab:orange',</span><spanclass="pre">'tab:green',</span>
<spanclass="pre">'tab:gray',</span><spanclass="pre">'tab:olive',</span><spanclass="pre">'tab:cyan'}</span></code> which are the Tableau Colors from the
‘T10’ categorical palette (which is the default color cycle);</li>
<li>a “CN” color spec, i.e. <codeclass="xref py py-obj docutils literal"><spanclass="pre">'C'</span></code> followed by a single digit, which is an index
into the default property cycle (<codeclass="docutils literal"><spanclass="pre">matplotlib.rcParams['axes.prop_cycle']</span></code>);
the indexing occurs at artist creation time and defaults to black if the
cycle does not include color.</li>
</ul>
<p>All string specifications of color, other than “CN”, are case-insensitive.</p>
<divclass="section" id="classes">
<h3>Classes<aclass="headerlink" href="#classes" title="Permalink to this headline">¶</a></h3>
<td>Dummy replacement for Normalize, 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-class docutils literal"><spanclass="pre">ScalarMappable</span></code></a> .</td>
<td>A class which, when called, can normalize data into the <codeclass="docutils literal"><spanclass="pre">[0.0,</span><spanclass="pre">1.0]</span></code> interval.</td>
<td>Normalize a given value to the <codeclass="docutils literal"><spanclass="pre">[0,</span><spanclass="pre">1]</span></code> interval with a power-law scaling.</td>