You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
<divid="unreleased-message"> You are reading an old version of the documentation (v3.2.2). For the latest version see <ahref="https://matplotlib.org/stable/api/contour_api.html">https://matplotlib.org/stable/api/contour_api.html</a></div>
<spanid="matplotlib-contour"></span><h1><codeclass="docutils literal notranslate"><spanclass="pre">matplotlib.contour</span></code><aclass="headerlink" href="#module-matplotlib.contour" title="Permalink to this headline">¶</a></h1>
<p>These are classes to support contour plotting and labelling for the Axes class.</p>
<td>{a numeric value in range 0-1000, 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'}</td>
<codeclass="descname">get_rotation</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/contour.html#ClabelText.get_rotation"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ClabelText.get_rotation" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the text angle as float in degrees.</p>
</dd></dl>
</dd></dl>
<dlclass="py class">
<dtid="matplotlib.contour.ContourLabeler">
<emclass="property">class </em><codeclass="descclassname">matplotlib.contour.</code><codeclass="descname">ContourLabeler</code><aclass="reference internal" href="../_modules/matplotlib/contour.html#ContourLabeler"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ContourLabeler" title="Permalink to this definition">¶</a></dt>
<p>Mixin to provide labelling capability to <aclass="reference internal" href="#matplotlib.contour.ContourSet" title="matplotlib.contour.ContourSet"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">ContourSet</span></code></a>.</p>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>x, y</strong><spanclass="classifier">float</span></dt><dd><p>The approximate location of the label.</p>
</dd>
<dt><strong>inline</strong><spanclass="classifier">bool, optional, default: True</span></dt><dd><p>If <em>True</em> remove the segment of the contour beneath the label.</p>
</dd>
<dt><strong>inline_spacing</strong><spanclass="classifier">int, optional, default: 5</span></dt><dd><p>Space in pixels to leave on each side of label when placing
inline. This spacing will be exact for labels at locations where
the contour is straight, less so for labels on curved contours.</p>
<codeclass="descname">calc_label_rot_and_inline</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em>, <em><spanclass="n">slc</span></em>, <em><spanclass="n">ind</span></em>, <em><spanclass="n">lw</span></em>, <em><spanclass="n">lc</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">spacing</span><spanclass="o">=</span><spanclass="default_value">5</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/contour.html#ContourLabeler.calc_label_rot_and_inline"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ContourLabeler.calc_label_rot_and_inline" title="Permalink to this definition">¶</a></dt>
<dd><p>This function calculates the appropriate label rotation given
the linecontour coordinates in screen units, the index of the
label location and the label width.</p>
<p>It will also break contour and calculate inlining if <em>lc</em> is
not empty (lc defaults to the empty list if None). <em>spacing</em>
is the space around the label in pixels to leave empty.</p>
<p>Do both of these tasks at once to avoid calculating path lengths
multiple times, which is relatively costly.</p>
<p>The method used here involves calculating the path length
along the contour in pixel coordinates and then looking
approximately label width / 2 away from central point to
determine rotation and then to break contour if desired.</p>
</dd></dl>
<dlclass="py method">
<dtid="matplotlib.contour.ContourLabeler.clabel">
<codeclass="descname">clabel</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em>, <em><spanclass="n">levels</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="o">*</span></em>, <em><spanclass="n">fontsize</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">inline</span><spanclass="o">=</span><spanclass="default_value">True</span></em>, <em><spanclass="n">inline_spacing</span><spanclass="o">=</span><spanclass="default_value">5</span></em>, <em><spanclass="n">fmt</span><spanclass="o">=</span><spanclass="default_value">'%1.3f'</span></em>, <em><spanclass="n">colors</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">use_clabeltext</span><spanclass="o">=</span><spanclass="default_value">False</span></em>, <em><spanclass="n">manual</span><spanclass="o">=</span><spanclass="default_value">False</span></em>, <em><spanclass="n">rightside_up</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/contour.html#ContourLabeler.clabel"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ContourLabeler.clabel" title="Permalink to this definition">¶</a></dt>
<dd><p>Label a contour plot.</p>
<p>Adds labels to line contours in this <aclass="reference internal" href="#matplotlib.contour.ContourSet" title="matplotlib.contour.ContourSet"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">ContourSet</span></code></a> (which inherits from
<dt><strong>levels</strong><spanclass="classifier">array-like, optional</span></dt><dd><p>A list of level values, that should be labeled. The list must be
a subset of <codeclass="docutils literal notranslate"><spanclass="pre">cs.levels</span></code>. If not given, all levels are labeled.</p>
</dd>
<dt><strong>fontsize</strong><spanclass="classifier">str or float, optional</span></dt><dd><p>Size in points or relative size e.g., 'smaller', 'x-large'.
See <aclass="reference internal" href="text_api.html#matplotlib.text.Text.set_size" title="matplotlib.text.Text.set_size"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Text.set_size</span></code></a> for accepted string values.</p>
<li>If <em>None</em>, the color of each label matches the color of
the corresponding contour.</li>
<li>If one string color, e.g., <em>colors</em> = 'r' or <em>colors</em> =
'red', all labels will be plotted in this color.</li>
<li>If a tuple of matplotlib color args (string, float, rgb, etc),
different labels will be plotted in different colors in the order
specified.</li>
</ul>
</dd>
<dt><strong>inline</strong><spanclass="classifier">bool, optional</span></dt><dd><p>If <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code> the underlying contour is removed where the label is
placed. Default is <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code>.</p>
</dd>
<dt><strong>inline_spacing</strong><spanclass="classifier">float, optional</span></dt><dd><p>Space in pixels to leave on each side of label when
placing inline. Defaults to 5.</p>
<p>This spacing will be exact for labels at locations where the
contour is straight, less so for labels on curved contours.</p>
</dd>
<dt><strong>fmt</strong><spanclass="classifier">str or dict, optional</span></dt><dd><p>A format string for the label. Default is '%1.3f'</p>
<p>Alternatively, this can be a dictionary matching contour levels
with arbitrary strings to use for each contour level (i.e.,
fmt[level]=string), or it can be any callable, such as a
<aclass="reference internal" href="ticker_api.html#matplotlib.ticker.Formatter" title="matplotlib.ticker.Formatter"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Formatter</span></code></a> instance, that returns a string when called with a
numeric contour level.</p>
</dd>
<dt><strong>manual</strong><spanclass="classifier">bool or iterable, optional</span></dt><dd><p>If <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code>, contour labels will be placed manually using
mouse clicks. Click the first button near a contour to
add a label, click the second button (or potentially both
mouse buttons at once) to finish adding labels. The third
button can be used to remove the last label added, but
only if labels are not inline. Alternatively, the keyboard
can be used to select label locations (enter to end label
placement, delete or backspace act like the third mouse button,
and any other key will select a label location).</p>
<p><em>manual</em> can also be an iterable object of (x, y) tuples.
Contour labels will be created as if mouse is clicked at each
(x, y) position.</p>
</dd>
<dt><strong>rightside_up</strong><spanclass="classifier">bool, optional</span></dt><dd><p>If <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code>, label rotations will always be plus
or minus 90 degrees from level. Default is <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code>.</p>
</dd>
<dt><strong>use_clabeltext</strong><spanclass="classifier">bool, optional</span></dt><dd><p>If <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code>, <aclass="reference internal" href="#matplotlib.contour.ClabelText" title="matplotlib.contour.ClabelText"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">ClabelText</span></code></a> class (instead of <aclass="reference internal" href="text_api.html#matplotlib.text.Text" title="matplotlib.text.Text"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Text</span></code></a>) is used to
of texts during the drawing time, therefore this can be used if
aspect of the axes changes. Default is <codeclass="docutils literal notranslate"><spanclass="pre">False</span></code>.</p>
</dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body"><dlclass="first last docutils">
<dt>labels</dt><dd><p>A list of <aclass="reference internal" href="text_api.html#matplotlib.text.Text" title="matplotlib.text.Text"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Text</span></code></a> instances for the labels.</p>
<codeclass="descname">get_text</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em>, <em><spanclass="n">lev</span></em>, <em><spanclass="n">fmt</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/contour.html#ContourLabeler.get_text"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ContourLabeler.get_text" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the text of the label.</p>
</dd></dl>
<dlclass="py method">
<dtid="matplotlib.contour.ContourLabeler.labels">
<codeclass="descname">labels</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em>, <em><spanclass="n">inline</span></em>, <em><spanclass="n">inline_spacing</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/contour.html#ContourLabeler.labels"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ContourLabeler.labels" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">locate_label</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em>, <em><spanclass="n">linecontour</span></em>, <em><spanclass="n">labelwidth</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/contour.html#ContourLabeler.locate_label"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ContourLabeler.locate_label" title="Permalink to this definition">¶</a></dt>
<dd><p>Find good place to draw a label (relatively flat part of the contour).</p>
<codeclass="descname">pop_label</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em>, <em><spanclass="n">index</span><spanclass="o">=</span><spanclass="default_value">- 1</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/contour.html#ContourLabeler.pop_label"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ContourLabeler.pop_label" title="Permalink to this definition">¶</a></dt>
<dd><p>Defaults to removing last label, but any index can be supplied</p>
<codeclass="descname">print_label</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em>, <em><spanclass="n">linecontour</span></em>, <em><spanclass="n">labelwidth</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/contour.html#ContourLabeler.print_label"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ContourLabeler.print_label" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <em>False</em> if contours are too short for a label.</p>
<dt><strong>levels</strong><spanclass="classifier">[level0, level1, ..., leveln]</span></dt><dd><p>A list of floating point numbers indicating the contour
levels.</p>
</dd>
<dt><strong>allsegs</strong><spanclass="classifier">[level0segs, level1segs, ...]</span></dt><dd><p>List of all the polygon segments for all the <em>levels</em>.
For contour lines <codeclass="docutils literal notranslate"><spanclass="pre">len(allsegs)</span><spanclass="pre">==</span><spanclass="pre">len(levels)</span></code>, and for
filled contour regions <codeclass="docutils literal notranslate"><spanclass="pre">len(allsegs)</span><spanclass="pre">=</span><spanclass="pre">len(levels)-1</span></code>. The lists
<dt><strong>allkinds</strong><spanclass="classifier"><codeclass="docutils literal notranslate"><spanclass="pre">None</span></code> or [level0kinds, level1kinds, ...]</span></dt><dd><p>Optional list of all the polygon vertex kinds (code types), as
described and used in Path. This is used to allow multiply-
connected paths such as holes within filled polygons.
If not <codeclass="docutils literal notranslate"><spanclass="pre">None</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">len(allkinds)</span><spanclass="pre">==</span><spanclass="pre">len(allsegs)</span></code>. The lists
<dt><strong>levels</strong><spanclass="classifier">[level0, level1, ..., leveln]</span></dt><dd><p>A list of floating point numbers indicating the contour
levels.</p>
</dd>
<dt><strong>allsegs</strong><spanclass="classifier">[level0segs, level1segs, ...]</span></dt><dd><p>List of all the polygon segments for all the <em>levels</em>.
For contour lines <codeclass="docutils literal notranslate"><spanclass="pre">len(allsegs)</span><spanclass="pre">==</span><spanclass="pre">len(levels)</span></code>, and for
filled contour regions <codeclass="docutils literal notranslate"><spanclass="pre">len(allsegs)</span><spanclass="pre">=</span><spanclass="pre">len(levels)-1</span></code>. The lists
<dt><strong>allkinds</strong><spanclass="classifier">[level0kinds, level1kinds, ...], optional</span></dt><dd><p>Optional list of all the polygon vertex kinds (code types), as
described and used in Path. This is used to allow multiply-
connected paths such as holes within filled polygons.
If not <codeclass="docutils literal notranslate"><spanclass="pre">None</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">len(allkinds)</span><spanclass="pre">==</span><spanclass="pre">len(allsegs)</span></code>. The lists
<codeclass="descname">changed</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/contour.html#ContourSet.changed"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ContourSet.changed" title="Permalink to this definition">¶</a></dt>
<dd><p>Call this whenever the mappable is changed to notify all the
<codeclass="descname">find_nearest_contour</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em>, <em><spanclass="n">x</span></em>, <em><spanclass="n">y</span></em>, <em><spanclass="n">indices</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">pixel</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/contour.html#ContourSet.find_nearest_contour"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ContourSet.find_nearest_contour" title="Permalink to this definition">¶</a></dt>
<dd><p>Finds contour that is closest to a point. Defaults to
measuring distance in pixels (screen space - useful for manual
contour labeling), but this can be controlled via a keyword
argument.</p>
<p>Returns a tuple containing the contour, segment, index of
segment, x & y of segment point and distance to minimum point.</p>
<p>Optional keyword arguments:</p>
<blockquote>
<div><dlclass="docutils">
<dt><em>indices</em>:</dt><dd>Indexes of contour levels to consider when looking for
nearest point. Defaults to using all levels.</dd>
<dt><em>pixel</em>:</dt><dd>If <em>True</em>, measure distance in pixel space, if not, measure
distance in axes space. Defaults to <em>True</em>.</dd>
</dl>
</div></blockquote>
</dd></dl>
<dlclass="py method">
<dtid="matplotlib.contour.ContourSet.get_alpha">
<codeclass="descname">get_alpha</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/contour.html#ContourSet.get_alpha"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ContourSet.get_alpha" title="Permalink to this definition">¶</a></dt>
<dd><p>returns alpha to be applied to all ContourSet artists</p>
<codeclass="descname">get_transform</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/contour.html#ContourSet.get_transform"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ContourSet.get_transform" title="Permalink to this definition">¶</a></dt>
<dt><strong>variable_name</strong><spanclass="classifier">str</span></dt><dd><p>The string used inside the inequality used on the labels.</p>
</dd>
<dt><strong>str_format</strong><spanclass="classifier">function: float -> str</span></dt><dd><p>Function used to format the numbers in the labels.</p>
</dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>artists</strong><spanclass="classifier">List[<aclass="reference internal" href="artist_api.html#matplotlib.artist.Artist" title="matplotlib.artist.Artist"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Artist</span></code></a>]</span></dt><dd><p>A list of the artists.</p>
</dd>
<dt><strong>labels</strong><spanclass="classifier">List[str]</span></dt><dd><p>A list of the labels.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dlclass="py method">
<dtid="matplotlib.contour.ContourSet.set_alpha">
<codeclass="descname">set_alpha</code><spanclass="sig-paren">(</span><em><spanclass="n">self</span></em>, <em><spanclass="n">alpha</span></em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/contour.html#ContourSet.set_alpha"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.contour.ContourSet.set_alpha" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the alpha blending value for all ContourSet artists.
<em>alpha</em> must be between 0 (transparent) and 1 (opaque).</p>
<dt><strong>levels</strong><spanclass="classifier">[level0, level1, ..., leveln]</span></dt><dd><p>A list of floating point numbers indicating the contour
levels.</p>
</dd>
<dt><strong>allsegs</strong><spanclass="classifier">[level0segs, level1segs, ...]</span></dt><dd><p>List of all the polygon segments for all the <em>levels</em>.
For contour lines <codeclass="docutils literal notranslate"><spanclass="pre">len(allsegs)</span><spanclass="pre">==</span><spanclass="pre">len(levels)</span></code>, and for
filled contour regions <codeclass="docutils literal notranslate"><spanclass="pre">len(allsegs)</span><spanclass="pre">=</span><spanclass="pre">len(levels)-1</span></code>. The lists
<dt><strong>allkinds</strong><spanclass="classifier">[level0kinds, level1kinds, ...], optional</span></dt><dd><p>Optional list of all the polygon vertex kinds (code types), as
described and used in Path. This is used to allow multiply-
connected paths such as holes within filled polygons.
If not <codeclass="docutils literal notranslate"><spanclass="pre">None</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">len(allkinds)</span><spanclass="pre">==</span><spanclass="pre">len(allsegs)</span></code>. The lists