<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/cm_api.html">https://matplotlib.org/stable/api/cm_api.html</a></div>
<h1>cm (colormap)<aclass="headerlink" href="#cm-colormap" title="Permalink to this headline">¶</a></h1>
<divclass="section" id="module-matplotlib.cm">
<spanid="matplotlib-cm"></span><h2><aclass="reference internal" href="#module-matplotlib.cm" title="matplotlib.cm"><codeclass="xref py py-mod docutils literal"><spanclass="pre">matplotlib.cm</span></code></a><aclass="headerlink" href="#module-matplotlib.cm" title="Permalink to this headline">¶</a></h2>
<p>This module provides a large set of colormaps, functions for
registering new colormaps and for getting a colormap by name,
and a mixin class for adding color mapping functionality.</p>
<dlclass="class">
<dtid="matplotlib.cm.ScalarMappable">
<emclass="property">class </em><codeclass="descclassname">matplotlib.cm.</code><codeclass="descname">ScalarMappable</code><spanclass="sig-paren">(</span><em>norm=None</em>, <em>cmap=None</em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable" title="Permalink to this definition">¶</a></dt>
<div><p>The colormap used to map normalized data values to RGBA colors.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<dlclass="method">
<dtid="matplotlib.cm.ScalarMappable.add_checker">
<codeclass="descname">add_checker</code><spanclass="sig-paren">(</span><em>checker</em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.add_checker" title="Permalink to this definition">¶</a></dt>
<dd><p>Add an entry to a dictionary of boolean flags
that are set to True when the mappable is changed.</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.cm.ScalarMappable.autoscale">
<codeclass="descname">autoscale</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.autoscale" title="Permalink to this definition">¶</a></dt>
<dd><p>Autoscale the scalar limits on the norm instance using the
<codeclass="descname">autoscale_None</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.autoscale_None" title="Permalink to this definition">¶</a></dt>
<dd><p>Autoscale the scalar limits on the norm instance using the
current array, changing only limits that are None</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.cm.ScalarMappable.changed">
<codeclass="descname">changed</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.changed" title="Permalink to this definition">¶</a></dt>
<dd><p>Call this whenever the mappable is changed to notify all the
<codeclass="descname">check_update</code><spanclass="sig-paren">(</span><em>checker</em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.check_update" title="Permalink to this definition">¶</a></dt>
<dd><p>If mappable has changed since the last check,
return True; else return False</p>
</dd></dl>
<dlclass="attribute">
<dtid="matplotlib.cm.ScalarMappable.cmap">
<codeclass="descname">cmap</code><emclass="property"> = None</em><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.cmap" title="Permalink to this definition">¶</a></dt>
<dd><p>The Colormap instance of this ScalarMappable.</p>
</dd></dl>
<dlclass="attribute">
<dtid="matplotlib.cm.ScalarMappable.colorbar">
<codeclass="descname">colorbar</code><emclass="property"> = None</em><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.colorbar" title="Permalink to this definition">¶</a></dt>
<dd><p>The last colorbar associated with this ScalarMappable. May be None.</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.cm.ScalarMappable.get_array">
<codeclass="descname">get_array</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.get_array" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the array</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.cm.ScalarMappable.get_clim">
<codeclass="descname">get_clim</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.get_clim" title="Permalink to this definition">¶</a></dt>
<dd><p>return the min, max of the color limits for image scaling</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.cm.ScalarMappable.get_cmap">
<codeclass="descname">get_cmap</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.get_cmap" title="Permalink to this definition">¶</a></dt>
<dd><p>return the colormap</p>
</dd></dl>
<dlclass="attribute">
<dtid="matplotlib.cm.ScalarMappable.norm">
<codeclass="descname">norm</code><emclass="property"> = None</em><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.norm" title="Permalink to this definition">¶</a></dt>
<dd><p>The Normalization instance of this ScalarMappable.</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.cm.ScalarMappable.set_array">
<codeclass="descname">set_array</code><spanclass="sig-paren">(</span><em>A</em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.set_array" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the image array from numpy array <em>A</em>.</p>
<codeclass="descname">set_clim</code><spanclass="sig-paren">(</span><em>vmin=None</em>, <em>vmax=None</em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.set_clim" title="Permalink to this definition">¶</a></dt>
<dd><p>set the norm limits for image scaling; if <em>vmin</em> is a length2
sequence, interpret it as <codeclass="docutils literal"><spanclass="pre">(vmin,</span><spanclass="pre">vmax)</span></code> which is used to
support setp</p>
<p>ACCEPTS: a length 2 sequence of floats</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.cm.ScalarMappable.set_cmap">
<codeclass="descname">set_cmap</code><spanclass="sig-paren">(</span><em>cmap</em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.set_cmap" title="Permalink to this definition">¶</a></dt>
<dd><p>set the colormap for luminance data</p>
<p>ACCEPTS: a colormap or registered colormap name</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.cm.ScalarMappable.set_norm">
<codeclass="descname">set_norm</code><spanclass="sig-paren">(</span><em>norm</em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.set_norm" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">to_rgba</code><spanclass="sig-paren">(</span><em>x</em>, <em>alpha=None</em>, <em>bytes=False</em>, <em>norm=True</em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.to_rgba" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a normalized rgba array corresponding to <em>x</em>.</p>
<p>In the normal case, <em>x</em> is a 1-D or 2-D sequence of scalars, and
the corresponding ndarray of rgba values will be returned,
based on the norm and colormap set for this ScalarMappable.</p>
<p>There is one special case, for handling images that are already
rgb or rgba, such as might have been read from an image file.
If <em>x</em> is an ndarray with 3 dimensions,
and the last dimension is either 3 or 4, then it will be
treated as an rgb or rgba array, and no mapping will be done.
The array can be uint8, or it can be floating point with
values in the 0-1 range; otherwise a ValueError will be raised.
If it is a masked array, the mask will be ignored.
If the last dimension is 3, the <em>alpha</em> kwarg (defaulting to 1)
will be used to fill in the transparency. If the last dimension
is 4, the <em>alpha</em> kwarg is ignored; it does not
replace the pre-existing alpha. A ValueError will be raised
if the third dimension is other than 3 or 4.</p>
<p>In either case, if <em>bytes</em> is <em>False</em> (default), the rgba
array will be floats in the 0-1 range; if it is <em>True</em>,
the returned rgba array will be uint8 in the 0 to 255 range.</p>
<p>If norm is False, no normalization of the input data is
performed, and it is assumed to be in the range (0-1).</p>
</dd></dl>
</dd></dl>
<dlclass="function">
<dtid="matplotlib.cm.get_cmap">
<codeclass="descclassname">matplotlib.cm.</code><codeclass="descname">get_cmap</code><spanclass="sig-paren">(</span><em>name=None</em>, <em>lut=None</em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.get_cmap" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a colormap instance, defaulting to rc values if <em>name</em> is None.</p>
<p>Colormaps added with <aclass="reference internal" href="#matplotlib.cm.register_cmap" title="matplotlib.cm.register_cmap"><codeclass="xref py py-func docutils literal"><spanclass="pre">register_cmap()</span></code></a> take precedence over
built-in colormaps.</p>
<p>If <em>name</em> is a <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">matplotlib.colors.Colormap</span></code></a> instance, it will be
returned.</p>
<p>If <em>lut</em> is not None it must be an integer giving the number of
entries desired in the lookup table, and <em>name</em> must be a standard
mpl colormap name.</p>
</dd></dl>
<dlclass="function">
<dtid="matplotlib.cm.register_cmap">
<codeclass="descclassname">matplotlib.cm.</code><codeclass="descname">register_cmap</code><spanclass="sig-paren">(</span><em>name=None</em>, <em>cmap=None</em>, <em>data=None</em>, <em>lut=None</em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.register_cmap" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a colormap to the set recognized by <aclass="reference internal" href="#matplotlib.cm.get_cmap" title="matplotlib.cm.get_cmap"><codeclass="xref py py-func docutils literal"><spanclass="pre">get_cmap()</span></code></a>.</p>
<p>In the first case, <em>cmap</em> must be a <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">matplotlib.colors.Colormap</span></code></a>
instance. The <em>name</em> is optional; if absent, the name will
be the <codeclass="xref py py-attr docutils literal"><spanclass="pre">name</span></code> attribute of the <em>cmap</em>.</p>
<p>In the second case, the three arguments are passed to
the <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> initializer,
and the resulting colormap is registered.</p>
</dd></dl>
<dlclass="function">
<dtid="matplotlib.cm.revcmap">
<codeclass="descclassname">matplotlib.cm.</code><codeclass="descname">revcmap</code><spanclass="sig-paren">(</span><em>data</em><spanclass="sig-paren">)</span><aclass="headerlink" href="#matplotlib.cm.revcmap" title="Permalink to this definition">¶</a></dt>
<dd><p>Can only handle specification <em>data</em> in dictionary format.</p>