<divid="unreleased-message"> You are reading an old version of the documentation (v3.0.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>colors<aclass="headerlink" href="#colors" title="Permalink to this headline">¶</a></h1>
<p>For a visual representation of the Matplotlib colormaps, see:</p>
<ulclass="simple">
<li>The <aclass="reference internal" href="../gallery/index.html#color-examples"><spanclass="std std-ref">Color</span></a> examples for examples of controlling color with
Matplotlib.</li>
<li>The <aclass="reference internal" href="../tutorials/index.html#tutorials-colors"><spanclass="std std-ref">Colors</span></a> tutorial for an in-depth guide on controlling
<spanid="matplotlib-colors"></span><h2><aclass="reference internal" href="#module-matplotlib.colors" title="matplotlib.colors"><codeclass="xref py py-mod docutils literal notranslate"><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.</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-class 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-class docutils literal notranslate"><spanclass="pre">Colormap</span></code></a>. Two are provided here:
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-class 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-func 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-func docutils literal notranslate"><spanclass="pre">to_rgba()</span></code></a>) or to an HTML-like hex string in the
<codeclass="xref py py-obj docutils literal notranslate"><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 notranslate"><spanclass="pre">to_hex()</span></code></a>), and a sequence of colors to an <codeclass="xref py py-obj docutils literal notranslate"><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 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 tuple of float values in <codeclass="docutils literal notranslate"><spanclass="pre">[0,</span><spanclass="pre">1]</span></code> (e.g., <codeclass="docutils literal notranslate"><spanclass="pre">(0.1,</span><spanclass="pre">0.2,</span><spanclass="pre">0.5)</span></code>
or <codeclass="docutils literal notranslate"><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 notranslate"><spanclass="pre">'#0F0F0F'</span></code> or <codeclass="docutils literal notranslate"><spanclass="pre">'#0F0F0F0F'</span></code>);</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 <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>;</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 notranslate"><spanclass="pre">'xkcd:'</span></code> (e.g., <codeclass="docutils literal notranslate"><spanclass="pre">'xkcd:sky</span><spanclass="pre">blue'</span></code>);</li>
<li>one of <codeclass="docutils literal notranslate"><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 notranslate"><spanclass="pre">'C'</span></code> followed by a single digit, which is an index
into the default property cycle (<codeclass="docutils literal notranslate"><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 notranslate"><spanclass="pre">ScalarMappable</span></code></a> .</td>
<td>A class which, when called, can normalize data into the <codeclass="docutils literal notranslate"><spanclass="pre">[0.0,</span><spanclass="pre">1.0]</span></code> interval.</td>