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
<spanid="sphx-glr-tutorials-text-annotations-py"></span><h1><aclass="toc-backref" href="#id1">Annotations</a><aclass="headerlink" href="#annotations" title="Permalink to this headline">¶</a></h1>
<li><p><aclass="reference internal" href="#annotating-with-text-with-box" id="id4">Annotating with Text with Box</a></p></li>
<li><p><aclass="reference internal" href="#annotating-with-arrow" id="id5">Annotating with Arrow</a></p></li>
<li><p><aclass="reference internal" href="#placing-artist-at-the-anchored-location-of-the-axes" id="id6">Placing Artist at the anchored location of the Axes</a></p></li>
<li><p><aclass="reference internal" href="#using-complex-coordinates-with-annotations" id="id7">Using Complex Coordinates with Annotations</a></p></li>
<spanid="annotations-tutorial"></span><h2><aclass="toc-backref" href="#id2">Basic annotation</a><aclass="headerlink" href="#basic-annotation" title="Permalink to this headline">¶</a></h2>
<p>The uses of the basic <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.text.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">text()</span></code></a> will place text
at an arbitrary position on the Axes. A common use case of text is to
keyword arguments like <em>horizontalalignment</em>, <em>verticalalignment</em> and
<em>fontsize</em> are passed from <aclass="reference internal" href="../../api/_as_gen/matplotlib.axes.Axes.annotate.html#matplotlib.axes.Axes.annotate" title="matplotlib.axes.Axes.annotate"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">annotate</span></code></a> to the
<p>For more on all the wild and wonderful things you can do with
annotations, including fancy arrows, see <aclass="reference internal" href="#plotting-guide-annotation"><spanclass="std std-ref">Advanced Annotations</span></a>
and <aclass="reference internal" href="../../gallery/text_labels_and_annotations/annotation_demo.html"><spanclass="doc">Annotating Plots</span></a>.</p>
<p>Do not proceed unless you have already read <aclass="reference internal" href="#annotations-tutorial"><spanclass="std std-ref">Basic annotation</span></a>,
<spanid="plotting-guide-annotation"></span><h2><aclass="toc-backref" href="#id3">Advanced Annotations</a><aclass="headerlink" href="#advanced-annotations" title="Permalink to this headline">¶</a></h2>
<sectionid="annotating-with-text-with-box">
<h3><aclass="toc-backref" href="#id4">Annotating with Text with Box</a><aclass="headerlink" href="#annotating-with-text-with-box" title="Permalink to this headline">¶</a></h3>
<p><aclass="reference internal" href="../../api/_as_gen/matplotlib.axes.Axes.text.html#matplotlib.axes.Axes.text" title="matplotlib.axes.Axes.text"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">text</span></code></a> takes a <em>bbox</em> keyword argument, which draws a box around the
<h3><aclass="toc-backref" href="#id5">Annotating with Arrow</a><aclass="headerlink" href="#annotating-with-arrow" title="Permalink to this headline">¶</a></h3>
<p><aclass="reference internal" href="../../api/_as_gen/matplotlib.axes.Axes.annotate.html#matplotlib.axes.Axes.annotate" title="matplotlib.axes.Axes.annotate"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">annotate</span></code></a> draws an arrow connecting two points in an axes:</p>
<p>This annotates a point at <em>xy</em> in the given coordinate (<em>xycoords</em>)
with the text at <em>xytext</em> given in <em>textcoords</em>. Often, the
annotated point is specified in the <em>data</em> coordinate and the annotating
text in <em>offset points</em>.
See <aclass="reference internal" href="../../api/_as_gen/matplotlib.axes.Axes.annotate.html#matplotlib.axes.Axes.annotate" title="matplotlib.axes.Axes.annotate"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">annotate</span></code></a> for available coordinate systems.</p>
<p>An arrow connecting <em>xy</em> to <em>xytext</em> can be optionally drawn by
specifying the <em>arrowprops</em> argument. To draw only an arrow, use
<p>Note that "3" in <codeclass="docutils literal notranslate"><spanclass="pre">angle3</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">arc3</span></code> is meant to indicate that the
resulting path is a quadratic spline segment (three control
points). As will be discussed below, some arrow style options can only
be used when the connecting path is a quadratic spline.</p>
<p>The behavior of each connection style is (limitedly) demonstrated in the
example below. (Warning: The behavior of the <codeclass="docutils literal notranslate"><spanclass="pre">bar</span></code> style is currently not
well defined, it may be changed in the future).</p>
<p>Some arrowstyles only work with connection styles that generate a
quadratic-spline segment. They are <codeclass="docutils literal notranslate"><spanclass="pre">fancy</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">simple</span></code>, and <codeclass="docutils literal notranslate"><spanclass="pre">wedge</span></code>.
For these arrow styles, you must use the "angle3" or "arc3" connection
style.</p>
<p>If the annotation string is given, the patchA is set to the bbox patch
<p>As with <aclass="reference internal" href="../../api/_as_gen/matplotlib.axes.Axes.text.html#matplotlib.axes.Axes.text" title="matplotlib.axes.Axes.text"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">text</span></code></a>, a box around the text can be drawn using the <em>bbox</em>
<h3><aclass="toc-backref" href="#id6">Placing Artist at the anchored location of the Axes</a><aclass="headerlink" href="#placing-artist-at-the-anchored-location-of-the-axes" title="Permalink to this headline">¶</a></h3>
<p>There are classes of artists that can be placed at an anchored
location in the Axes. A common example is the legend. This type
of artist can be created by using the <aclass="reference internal" href="../../api/offsetbox_api.html#matplotlib.offsetbox.OffsetBox" title="matplotlib.offsetbox.OffsetBox"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">OffsetBox</span></code></a> class. A few
predefined classes are available in <aclass="reference internal" href="../../api/offsetbox_api.html#module-matplotlib.offsetbox" title="matplotlib.offsetbox"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">matplotlib.offsetbox</span></code></a> and in
<h3><aclass="toc-backref" href="#id7">Using Complex Coordinates with Annotations</a><aclass="headerlink" href="#using-complex-coordinates-with-annotations" title="Permalink to this headline">¶</a></h3>
<p>The Annotation in matplotlib supports several types of coordinates as
described in <aclass="reference internal" href="#annotations-tutorial"><spanclass="std std-ref">Basic annotation</span></a>. For an advanced user who wants
more control, it supports a few other options.</p>