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 (v2.0.2). 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-coordinates-with-annotations">Using Complex Coordinates with Annotations</a></li>
<li><aclass="reference internal" href="#annotating-with-text-with-box" id="id4">Annotating with Text with Box</a></li>
<li><aclass="reference internal" href="#annotating-with-arrow" id="id5">Annotating with Arrow</a></li>
<li><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></li>
<li><aclass="reference internal" href="#using-complex-coordinates-with-annotations" id="id7">Using Complex Coordinates with Annotations</a></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/pyplot_api.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><codeclass="xref py py-func docutils literal"><spanclass="pre">text()</span></code></a> will place text
at an arbitrary position on the Axes. A common use case of text is to
to make annotations easy. In an annotation, there are two points to
consider: the location being annotated represented by the argument
<codeclass="docutils literal"><spanclass="pre">xy</span></code> and the location of the text <codeclass="docutils literal"><spanclass="pre">xytext</span></code>. Both of these
arguments are <codeclass="docutils literal"><spanclass="pre">(x,y)</span></code> tuples.</p>
<p>In this example, both the <codeclass="docutils literal"><spanclass="pre">xy</span></code> (arrow tip) and <codeclass="docutils literal"><spanclass="pre">xytext</span></code> locations
(text location) are in data coordinates. There are a variety of other
coordinate systems one can choose – you can specify the coordinate
system of <codeclass="docutils literal"><spanclass="pre">xy</span></code> and <codeclass="docutils literal"><spanclass="pre">xytext</span></code> with one of the following strings for
<codeclass="docutils literal"><spanclass="pre">xycoords</span></code> and <codeclass="docutils literal"><spanclass="pre">textcoords</span></code> (default is ‘data’)</p>
keyword args like <codeclass="docutils literal"><spanclass="pre">horizontalalignment</span></code>, <codeclass="docutils literal"><spanclass="pre">verticalalignment</span></code> and
<codeclass="docutils literal"><spanclass="pre">fontsize</span></code> are passed from <codeclass="xref py py-obj docutils literal"><spanclass="pre">annotate</span></code> 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 Annotation</span></a>
and <aclass="reference internal" href="../examples/pylab_examples/annotation_demo.html#pylab-examples-annotation-demo"><spanclass="std std-ref">pylab_examples example code: annotation_demo.py</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 Annotation</a><aclass="headerlink" href="#advanced-annotation" title="Permalink to this headline">¶</a></h2>
<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>The <aclass="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><codeclass="xref py py-func docutils literal"><spanclass="pre">text()</span></code></a> function in the pyplot module (or
text method of the Axes class) takes bbox keyword argument, and when
<h3><aclass="toc-backref" href="#id5">Annotating with Arrow</a><aclass="headerlink" href="#annotating-with-arrow" title="Permalink to this headline">¶</a></h3>
<p>The <aclass="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.annotate" title="matplotlib.pyplot.annotate"><codeclass="xref py py-func docutils literal"><spanclass="pre">annotate()</span></code></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 <codeclass="docutils literal"><spanclass="pre">xy</span></code> in the given coordinate (<codeclass="docutils literal"><spanclass="pre">xycoords</span></code>)
with the text at <codeclass="docutils literal"><spanclass="pre">xytext</span></code> given in <codeclass="docutils literal"><spanclass="pre">textcoords</span></code>. 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"><codeclass="xref py py-func docutils literal"><spanclass="pre">annotate()</span></code></a> for available coordinate systems.</p>
<p>An arrow connecting two points (xy & xytext) can be optionally drawn by
specifying the <codeclass="docutils literal"><spanclass="pre">arrowprops</span></code> argument. To draw only an arrow, use
<p>Note that “3” in <codeclass="docutils literal"><spanclass="pre">angle3</span></code> and <codeclass="docutils literal"><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"><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"><spanclass="pre">fancy</span></code>, <codeclass="docutils literal"><spanclass="pre">simple</span></code>, and <codeclass="docutils literal"><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
<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 OffsetBox class. A few predefined classes are
available in <codeclass="docutils literal"><spanclass="pre">mpl_toolkits.axes_grid.anchored_artists</span></code>.</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="c1"># in data coordinates!</span>
<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>
<spanclass="n">an2</span><spanclass="o">=</span><spanclass="n">ax</span><spanclass="o">.</span><spanclass="n">annotate</span><spanclass="p">(</span><spanclass="s2">"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="c1"># (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 <em>an2</em> 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="../api/transformations.html#matplotlib.transforms.BboxBase" title="matplotlib.transforms.BboxBase"><codeclass="xref py py-class docutils literal"><spanclass="pre">BboxBase</span></code></a> or
<aclass="reference internal" href="../api/transformations.html#matplotlib.transforms.Transform" title="matplotlib.transforms.Transform"><codeclass="xref py py-class docutils literal"><spanclass="pre">Transform</span></code></a>. If a transform is
returned, it is the same as 1 and if a bbox is returned, it is the same
as 2. The callable object should take a single argument of the
renderer instance. For example, the following two commands give
<li><pclass="first">Sometimes, you want your annotation with some “offset points”, not from the
annotated point but from some other point.
<aclass="reference internal" href="../api/text_api.html#matplotlib.text.OffsetFrom" title="matplotlib.text.OffsetFrom"><codeclass="xref py py-class docutils literal"><spanclass="pre">OffsetFrom</span></code></a> is a helper class for such cases.</p>
<p>You may take a look at this example <aclass="reference internal" href="../examples/pylab_examples/annotation_demo3.html#pylab-examples-annotation-demo3"><spanclass="std std-ref">pylab_examples example code: annotation_demo3.py</span></a>.</p>
</li>
</ol>
</div></blockquote>
</div>
<divclass="section" id="using-connectorpatch">
<h3><aclass="toc-backref" href="#id8">Using ConnectorPatch</a><aclass="headerlink" href="#using-connectorpatch" title="Permalink to this headline">¶</a></h3>
<p>The ConnectorPatch is like an annotation without text. While the annotate
function is recommended in most situations, the ConnectorPatch is useful when
<h3><aclass="toc-backref" href="#id9">Zoom effect between Axes</a><aclass="headerlink" href="#zoom-effect-between-axes" title="Permalink to this headline">¶</a></h3>
<p>mpl_toolkits.axes_grid.inset_locator defines some patch classes useful
for interconnecting two axes. Understanding the code requires some
knowledge of how mpl’s transform works. But, utilizing it will be
<h3><aclass="toc-backref" href="#id10">Define Custom BoxStyle</a><aclass="headerlink" href="#define-custom-boxstyle" title="Permalink to this headline">¶</a></h3>
<p>You can use a custom box style. The value for the <codeclass="docutils literal"><spanclass="pre">boxstyle</span></code> can be a