<divid="unreleased-message"> You are reading an old version of the documentation (v3.1.3). For the latest version see <ahref="https://matplotlib.org/stable/api/colorbar_api.html">https://matplotlib.org/stable/api/colorbar_api.html</a></div>
<spanid="matplotlib-colorbar"></span><h1><codeclass="docutils literal notranslate"><spanclass="pre">matplotlib.colorbar</span></code><aclass="headerlink" href="#module-matplotlib.colorbar" title="Permalink to this headline">¶</a></h1>
<p>Colorbar toolkit with two classes and a function:</p>
and <aclass="reference internal" href="#matplotlib.colorbar.Colorbar" title="matplotlib.colorbar.Colorbar"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Colorbar</span></code></a>; the <aclass="reference internal" href="_as_gen/matplotlib.pyplot.colorbar.html#matplotlib.pyplot.colorbar" title="matplotlib.pyplot.colorbar"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">colorbar()</span></code></a> function
is a thin wrapper over <aclass="reference internal" href="_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure.colorbar" title="matplotlib.figure.Figure.colorbar"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">colorbar()</span></code></a>.</p>
<dlclass="class">
<dtid="matplotlib.colorbar.Colorbar">
<emclass="property">class </em><codeclass="descclassname">matplotlib.colorbar.</code><codeclass="descname">Colorbar</code><spanclass="sig-paren">(</span><em>ax</em>, <em>mappable</em>, <em>**kw</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#Colorbar"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.Colorbar" title="Permalink to this definition">¶</a></dt>
<p>This class connects a <aclass="reference internal" href="#matplotlib.colorbar.ColorbarBase" title="matplotlib.colorbar.ColorbarBase"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">ColorbarBase</span></code></a> to 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> such as a
<p>It is not intended to be instantiated directly; instead,
use <aclass="reference internal" href="_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure.colorbar" title="matplotlib.figure.Figure.colorbar"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">colorbar()</span></code></a> or
<aclass="reference internal" href="_as_gen/matplotlib.pyplot.colorbar.html#matplotlib.pyplot.colorbar" title="matplotlib.pyplot.colorbar"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">colorbar()</span></code></a> to make your colorbar.</p>
<dlclass="method">
<dtid="matplotlib.colorbar.Colorbar.add_lines">
<codeclass="descname">add_lines</code><spanclass="sig-paren">(</span><em>self</em>, <em>CS</em>, <em>erase=True</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#Colorbar.add_lines"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.Colorbar.add_lines" title="Permalink to this definition">¶</a></dt>
<dd><p>Add the lines from a non-filled
<aclass="reference internal" href="contour_api.html#matplotlib.contour.ContourSet" title="matplotlib.contour.ContourSet"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">ContourSet</span></code></a> to the colorbar.</p>
<p>Set <em>erase</em> to False if these lines should be added to
<codeclass="descname">on_mappable_changed</code><spanclass="sig-paren">(</span><em>self</em>, <em>mappable</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#Colorbar.on_mappable_changed"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.Colorbar.on_mappable_changed" title="Permalink to this definition">¶</a></dt>
<dd><p>Updates this colorbar to match the mappable's properties.</p>
<p>Typically this is automatically registered as an event handler
by <aclass="reference internal" href="#matplotlib.colorbar.colorbar_factory" title="matplotlib.colorbar.colorbar_factory"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">colorbar_factory()</span></code></a> and should not be called manually.</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.colorbar.Colorbar.remove">
<codeclass="descname">remove</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#Colorbar.remove"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.Colorbar.remove" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove this colorbar from the figure. If the colorbar was created with
<codeclass="docutils literal notranslate"><spanclass="pre">use_gridspec=True</span></code> then restore the gridspec to its previous value.</p>
<codeclass="descname">update_bruteforce</code><spanclass="sig-paren">(</span><em>self</em>, <em>mappable</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#Colorbar.update_bruteforce"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.Colorbar.update_bruteforce" title="Permalink to this definition">¶</a></dt>
<dd><p>Destroy and rebuild the colorbar. This is
intended to become obsolete, and will probably be
deprecated and then removed. It is not called when
the pyplot.colorbar function or the Figure.colorbar
<codeclass="descname">update_normal</code><spanclass="sig-paren">(</span><em>self</em>, <em>mappable</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#Colorbar.update_normal"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.Colorbar.update_normal" title="Permalink to this definition">¶</a></dt>
<dd><p>Update solid patches, lines, etc.</p>
<p>Unlike <aclass="reference internal" href="#matplotlib.colorbar.Colorbar.update_bruteforce" title="matplotlib.colorbar.Colorbar.update_bruteforce"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">update_bruteforce</span></code></a>, this does not clear the axes. This is
meant to be called when the norm of the image or contour plot to which
this colorbar belongs changes.</p>
<p>If the norm on the mappable is different than before, this resets the
locator and formatter for the axis, so if these have been customized,
they will need to be customized again. However, if the norm only
changes values of <em>vmin</em>, <em>vmax</em> or <em>cmap</em> then the old formatter
<p>This is a base class for the <aclass="reference internal" href="#matplotlib.colorbar.Colorbar" title="matplotlib.colorbar.Colorbar"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Colorbar</span></code></a> class, which is the
basis for the <aclass="reference internal" href="_as_gen/matplotlib.pyplot.colorbar.html#matplotlib.pyplot.colorbar" title="matplotlib.pyplot.colorbar"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">colorbar()</span></code></a> function and the
<aclass="reference internal" href="_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure.colorbar" title="matplotlib.figure.Figure.colorbar"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">colorbar()</span></code></a> method, which are the
usual ways of creating a colorbar.</p>
<p>It is also useful by itself for showing a colormap. If the <em>cmap</em>
kwarg is given but <em>boundaries</em> and <em>values</em> are left as None,
then the colormap will be displayed on a 0-1 scale. To show the
under- and over-value colors, specify the <em>norm</em> as:</p>
<dd><pclass="first last">The <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Axes</span></code> instance in which the colorbar is drawn.</p>
<dd><pclass="first last">A list of <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">LineCollection</span></code> if lines were drawn, otherwise
<codeclass="descname">add_lines</code><spanclass="sig-paren">(</span><em>self</em>, <em>levels</em>, <em>colors</em>, <em>linewidths</em>, <em>erase=True</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#ColorbarBase.add_lines"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.add_lines" title="Permalink to this definition">¶</a></dt>
<dd><p>Draw lines on the colorbar.</p>
<p><em>colors</em> and <em>linewidths</em> must be scalars or
sequences the same length as <em>levels</em>.</p>
<p>Set <em>erase</em> to False to add lines without first
removing any previously added lines.</p>
</dd></dl>
<dlclass="attribute">
<dtid="matplotlib.colorbar.ColorbarBase.ax">
<codeclass="descname">ax</code><emclass="property"> = None</em><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.ax" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">config_axis</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#ColorbarBase.config_axis"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.config_axis" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">draw_all</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#ColorbarBase.draw_all"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.draw_all" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate any free parameters based on the current cmap and norm,
<codeclass="descname">get_ticks</code><spanclass="sig-paren">(</span><em>self</em>, <em>minor=False</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#ColorbarBase.get_ticks"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.get_ticks" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the x ticks as a list of locations.</p>
<codeclass="descname">minorticks_off</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#ColorbarBase.minorticks_off"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.minorticks_off" title="Permalink to this definition">¶</a></dt>
<dd><p>Turns off the minor ticks on the colorbar.</p>
<codeclass="descname">minorticks_on</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#ColorbarBase.minorticks_on"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.minorticks_on" title="Permalink to this definition">¶</a></dt>
<dd><p>Turns on the minor ticks on the colorbar without extruding
<codeclass="descname">n_rasterize</code><emclass="property"> = 50</em><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.n_rasterize" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="method">
<dtid="matplotlib.colorbar.ColorbarBase.remove">
<codeclass="descname">remove</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#ColorbarBase.remove"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.remove" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">set_alpha</code><spanclass="sig-paren">(</span><em>self</em>, <em>alpha</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#ColorbarBase.set_alpha"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.set_alpha" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">set_label</code><spanclass="sig-paren">(</span><em>self</em>, <em>label</em>, <em>**kw</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#ColorbarBase.set_label"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.set_label" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">set_ticklabels</code><spanclass="sig-paren">(</span><em>self</em>, <em>ticklabels</em>, <em>update_ticks=True</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#ColorbarBase.set_ticklabels"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.set_ticklabels" title="Permalink to this definition">¶</a></dt>
<dd><p>Set tick labels.</p>
<p>Tick labels are updated immediately unless <em>update_ticks</em> is <em>False</em>,
in which case one should call <aclass="reference internal" href="#matplotlib.colorbar.ColorbarBase.update_ticks" title="matplotlib.colorbar.ColorbarBase.update_ticks"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">update_ticks</span></code></a> explicitly.</p>
<codeclass="descname">set_ticks</code><spanclass="sig-paren">(</span><em>self</em>, <em>ticks</em>, <em>update_ticks=True</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#ColorbarBase.set_ticks"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.set_ticks" title="Permalink to this definition">¶</a></dt>
<dd><pclass="first last">If True, tick locations are updated immediately. If False,
use <aclass="reference internal" href="#matplotlib.colorbar.ColorbarBase.update_ticks" title="matplotlib.colorbar.ColorbarBase.update_ticks"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">update_ticks()</span></code></a> to manually update the ticks.</p>
<codeclass="descname">update_ticks</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#ColorbarBase.update_ticks"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.ColorbarBase.update_ticks" title="Permalink to this definition">¶</a></dt>
<dd><p>Force the update of the ticks and ticklabels. This must be
called whenever the tick locator and/or tick formatter changes.</p>
</dd></dl>
</dd></dl>
<dlclass="class">
<dtid="matplotlib.colorbar.ColorbarPatch">
<emclass="property">class </em><codeclass="descclassname">matplotlib.colorbar.</code><codeclass="descname">ColorbarPatch</code><spanclass="sig-paren">(</span><em>ax</em>, <em>mappable</em>, <em>**kw</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#ColorbarPatch"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.ColorbarPatch" title="Permalink to this definition">¶</a></dt>
<p>A Colorbar which is created using <aclass="reference internal" href="_as_gen/matplotlib.patches.Patch.html#matplotlib.patches.Patch" title="matplotlib.patches.Patch"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Patch</span></code></a>
rather than the default <codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">pcolor()</span></code>.</p>
<p>It uses a list of Patch instances instead of a
<aclass="reference internal" href="collections_api.html#matplotlib.collections.PatchCollection" title="matplotlib.collections.PatchCollection"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">PatchCollection</span></code></a> because the
latter does not allow the hatch pattern to vary among the
members of the collection.</p>
</dd></dl>
<dlclass="function">
<dtid="matplotlib.colorbar.colorbar_factory">
<codeclass="descclassname">matplotlib.colorbar.</code><codeclass="descname">colorbar_factory</code><spanclass="sig-paren">(</span><em>cax</em>, <em>mappable</em>, <em>**kwargs</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/colorbar.html#colorbar_factory"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.colorbar.colorbar_factory" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a colorbar on the given axes for the given mappable.</p>
<p>Typically, for automatic colorbar placement given only a mappable use