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 (v1.2.1). For the latest version see <ahref="/stable/">https://matplotlib.org/stable/</a></div>
<li><aclass="reference internal" href="#annotating-with-text-with-box">Annotating with Text with Box</a></li>
<li><aclass="reference internal" href="#annotating-with-arrow">Annotating with Arrow</a></li>
<li><aclass="reference internal" href="#placing-artist-at-the-anchored-location-of-the-axes">Placing Artist at the anchored location of the Axes</a></li>
<li><aclass="reference internal" href="#using-complex-coordinate-with-annotation">Using Complex Coordinate with Annotation</a></li>
<spanid="plotting-guide-annotation"></span><h1>Annotating Axes<aclass="headerlink" href="#annotating-axes" title="Permalink to this headline">¶</a></h1>
<p>Do not proceed unless you already have read <aclass="reference internal" href="annotations_intro.html#annotations-tutorial"><em>Annotating text</em></a>,
<aclass="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><ttclass="xref py py-func docutils literal"><spanclass="pre">text()</span></tt></a> and
<p>The <aclass="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><ttclass="xref py py-func docutils literal"><spanclass="pre">text()</span></tt></a> function in the pyplot module (or
text method of the Axes class) takes bbox keyword argument, and when
<h2>Annotating with Arrow<aclass="headerlink" href="#annotating-with-arrow" title="Permalink to this headline">¶</a></h2>
<p>The <aclass="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.annotate" title="matplotlib.pyplot.annotate"><ttclass="xref py py-func docutils literal"><spanclass="pre">annotate()</span></tt></a> function in the pyplot module
(or annotate method of the Axes class) is used to draw an arrow
<p>This annotates a point at <ttclass="docutils literal"><spanclass="pre">xy</span></tt> in the given coordinate (<ttclass="docutils literal"><spanclass="pre">xycoords</span></tt>)
with the text at <ttclass="docutils literal"><spanclass="pre">xytext</span></tt> given in <ttclass="docutils literal"><spanclass="pre">textcoords</span></tt>. 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/pyplot_api.html#matplotlib.pyplot.annotate" title="matplotlib.pyplot.annotate"><ttclass="xref py py-func docutils literal"><spanclass="pre">annotate()</span></tt></a> for available coordinate systems.</p>
<p>An arrow connecting two point (xy & xytext) can be optionally drawn by
specifying the <ttclass="docutils literal"><spanclass="pre">arrowprops</span></tt> argument. To draw only an arrow, use
<p>Note that “3” in <ttclass="docutils literal"><spanclass="pre">angle3</span></tt> and <ttclass="docutils literal"><spanclass="pre">arc3</span></tt> is meant to indicate that the
resulting path is a quadratic spline segment (three control
points). As will be discussed below, some arrow style option only can
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 <ttclass="docutils literal"><spanclass="pre">bar</span></tt> style is currently not
well defined, it may be changed in the future).</p>
<p>Some arrowstyles only work with connection style that generates a
quadratic-spline segment. They are <ttclass="docutils literal"><spanclass="pre">fancy</span></tt>, <ttclass="docutils literal"><spanclass="pre">simple</span></tt>, and <ttclass="docutils literal"><spanclass="pre">wedge</span></tt>.
For these arrow styles, you must use “angle3” or “arc3” connection
style.</p>
<p>If the annotation string is given, the patchA is set to the bbox patch
<h2>Placing Artist at the anchored location of the Axes<aclass="headerlink" href="#placing-artist-at-the-anchored-location-of-the-axes" title="Permalink to this headline">¶</a></h2>
<p>There are class of artist that can be placed at the anchored location
of the Axes. A common example is the legend. This type of artists can
be created by using the OffsetBox class. A few predefined classes are
available in <ttclass="docutils literal"><spanclass="pre">mpl_toolkits.axes_grid.anchored_artists</span></tt>.</p>
<spanclass="n">el</span><spanclass="o">=</span><spanclass="n">Ellipse</span><spanclass="p">((</span><spanclass="mi">0</span><spanclass="p">,</span><spanclass="mi">0</span><spanclass="p">),</span><spanclass="n">width</span><spanclass="o">=</span><spanclass="mf">0.1</span><spanclass="p">,</span><spanclass="n">height</span><spanclass="o">=</span><spanclass="mf">0.4</span><spanclass="p">,</span><spanclass="n">angle</span><spanclass="o">=</span><spanclass="mi">30</span><spanclass="p">)</span><spanclass="c"># in data coordinates!</span>
<h2>Using Complex Coordinate with Annotation<aclass="headerlink" href="#using-complex-coordinate-with-annotation" title="Permalink to this headline">¶</a></h2>
<p>The Annotation in matplotlib support several types of coordinate as
described in <aclass="reference internal" href="annotations_intro.html#annotations-tutorial"><em>Annotating text</em></a>. For an advanced user who wants
more control, it supports a few other options.</p>
<spanclass="n">an2</span><spanclass="o">=</span><spanclass="n">ax</span><spanclass="o">.</span><spanclass="n">annotate</span><spanclass="p">(</span><spanclass="s">"Test 2"</span><spanclass="p">,</span><spanclass="n">xy</span><spanclass="o">=</span><spanclass="p">(</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="mf">0.5</span><spanclass="p">),</span><spanclass="n">xycoords</span><spanclass="o">=</span><spanclass="n">an1</span><spanclass="p">,</span><spanclass="c"># (1,0.5) of the an1's bbox</span>
<p>Note that it is your responsibility that the extent of the
coordinate artist (<em>an1</em> in above example) is determined before <em>an2</em>
gets drawn. In most cases, it means that an2 needs to be drawn
later than <em>an1</em>.</p>
</li>
<li><pclass="first">A callable object that returns an instance of either
<aclass="reference internal" href="../devel/transformations.html#matplotlib.transforms.BboxBase" title="matplotlib.transforms.BboxBase"><ttclass="xref py py-class docutils literal"><spanclass="pre">BboxBase</span></tt></a> or
<aclass="reference internal" href="../devel/transformations.html#matplotlib.transforms.Transform" title="matplotlib.transforms.Transform"><ttclass="xref py py-class docutils literal"><spanclass="pre">Transform</span></tt></a>. If a transform is
returned, it is same as 1 and if bbox is returned, it is same
as 2. The callable object should take a single argument of
renderer instance. For example, following two commands give
<li><pclass="first">Sometimes, you want your annotation with some “offset points”, but
not from the annotated point but from other
point. <aclass="reference internal" href="../api/artist_api.html#matplotlib.text.OffsetFrom" title="matplotlib.text.OffsetFrom"><ttclass="xref py py-class docutils literal"><spanclass="pre">OffsetFrom</span></tt></a> is a helper class for such
<p>You may take a look at this example <aclass="reference internal" href="../examples/pylab_examples/annotation_demo3.html#pylab-examples-annotation-demo3"><em>pylab_examples example code: annotation_demo3.py</em></a>.</p>
</li>
</ol>
</div></blockquote>
</div>
<divclass="section" id="using-connectorpatch">
<h2>Using ConnectorPatch<aclass="headerlink" href="#using-connectorpatch" title="Permalink to this headline">¶</a></h2>
<p>The ConnectorPatch is like an annotation without a text. While the
annotate function is recommended in most of situation, the
ConnectorPatch is useful when you want to connect points in different