<divid="unreleased-message"> You are reading an old version of the documentation (v1.3.1). 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"><ttclass="xref py py-mod docutils literal"><spanclass="pre">matplotlib.cm</span></tt></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><ttclass="descclassname">matplotlib.cm.</tt><ttclass="descname">ScalarMappable</tt><big>(</big><em>norm=None</em>, <em>cmap=None</em><big>)</big><aclass="headerlink" href="#matplotlib.cm.ScalarMappable" title="Permalink to this definition">¶</a></dt>
<dd><p>This is a mixin class to support scalar data to RGBA mapping.
The ScalarMappable makes use of data normalization before returning
<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">
<ttclass="descname">add_checker</tt><big>(</big><em>checker</em><big>)</big><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">
<ttclass="descname">autoscale</tt><big>(</big><big>)</big><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
<ttclass="descname">autoscale_None</tt><big>(</big><big>)</big><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">
<ttclass="descname">changed</tt><big>(</big><big>)</big><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
callbackSM listeners to the ‘changed’ signal</p>
<ttclass="descname">check_update</tt><big>(</big><em>checker</em><big>)</big><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">
<ttclass="descname">cmap</tt><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">
<ttclass="descname">colorbar</tt><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">
<ttclass="descname">get_array</tt><big>(</big><big>)</big><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">
<ttclass="descname">get_clim</tt><big>(</big><big>)</big><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">
<ttclass="descname">get_cmap</tt><big>(</big><big>)</big><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">
<ttclass="descname">norm</tt><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">
<ttclass="descname">set_array</tt><big>(</big><em>A</em><big>)</big><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>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.cm.ScalarMappable.set_clim">
<ttclass="descname">set_clim</tt><big>(</big><em>vmin=None</em>, <em>vmax=None</em><big>)</big><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 <ttclass="docutils literal"><spanclass="pre">(vmin,</span><spanclass="pre">vmax)</span></tt> 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">
<ttclass="descname">set_cmap</tt><big>(</big><em>cmap</em><big>)</big><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>
<ttclass="descname">set_colorbar</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.set_colorbar" title="Permalink to this definition">¶</a></dt>
<dd><divclass="deprecated">
<p><span>Deprecated since version 1.3: </span>The set_colorbar function was deprecated in version 1.3. Use the colorbar attribute instead.</p>
</div>
<p>set the colorbar and axes instances associated with mappable</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.cm.ScalarMappable.set_norm">
<ttclass="descname">set_norm</tt><big>(</big><em>norm</em><big>)</big><aclass="headerlink" href="#matplotlib.cm.ScalarMappable.set_norm" title="Permalink to this definition">¶</a></dt>
<dd><p>set the normalization instance</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.cm.ScalarMappable.to_rgba">
<ttclass="descname">to_rgba</tt><big>(</big><em>x</em>, <em>alpha=None</em>, <em>bytes=False</em><big>)</big><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.
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>Note: this method assumes the input is well-behaved; it does
not check for anomalies such as <em>x</em> being a masked rgba
array, or being an integer type other than uint8, or being
a floating point rgba array with values outside the 0-1 range.</p>
</dd></dl>
</dd></dl>
<dlclass="function">
<dtid="matplotlib.cm.get_cmap">
<ttclass="descclassname">matplotlib.cm.</tt><ttclass="descname">get_cmap</tt><big>(</big><em>name=None</em>, <em>lut=None</em><big>)</big><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"><ttclass="xref py py-func docutils literal"><spanclass="pre">register_cmap()</span></tt></a> take precedence over
built-in colormaps.</p>
<p>If <em>name</em> is a <aclass="reference internal" href="colors_api.html#matplotlib.colors.Colormap" title="matplotlib.colors.Colormap"><ttclass="xref py py-class docutils literal"><spanclass="pre">matplotlib.colors.Colormap</span></tt></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 with a corresponding data dictionary
in <em>datad</em>.</p>
</dd></dl>
<dlclass="function">
<dtid="matplotlib.cm.register_cmap">
<ttclass="descclassname">matplotlib.cm.</tt><ttclass="descname">register_cmap</tt><big>(</big><em>name=None</em>, <em>cmap=None</em>, <em>data=None</em>, <em>lut=None</em><big>)</big><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"><ttclass="xref py py-func docutils literal"><spanclass="pre">get_cmap()</span></tt></a>.</p>
<p>In the first case, <em>cmap</em> must be a <aclass="reference internal" href="colors_api.html#matplotlib.colors.Colormap" title="matplotlib.colors.Colormap"><ttclass="xref py py-class docutils literal"><spanclass="pre">matplotlib.colors.Colormap</span></tt></a>
instance. The <em>name</em> is optional; if absent, the name will
be the <ttclass="xref py py-attr docutils literal"><spanclass="pre">name</span></tt> attribute of the <em>cmap</em>.</p>
<p>In the second case, the three arguments are passed to
the <aclass="reference internal" href="colors_api.html#matplotlib.colors.LinearSegmentedColormap" title="matplotlib.colors.LinearSegmentedColormap"><ttclass="xref py py-class docutils literal"><spanclass="pre">LinearSegmentedColormap</span></tt></a> initializer,
and the resulting colormap is registered.</p>
</dd></dl>
<dlclass="function">
<dtid="matplotlib.cm.revcmap">
<ttclass="descclassname">matplotlib.cm.</tt><ttclass="descname">revcmap</tt><big>(</big><em>data</em><big>)</big><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>