<divid="unreleased-message"> You are reading an old version of the documentation (v1.4.3). For the latest version see <ahref="https://matplotlib.org/stable/devel/documenting_mpl.html">https://matplotlib.org/stable/devel/documenting_mpl.html</a></div>
<h2>Organization of matplotlib’s documentation<aclass="headerlink" href="#organization-of-matplotlib-s-documentation" title="Permalink to this headline">¶</a></h2>
<p>The actual ReStructured Text files are kept in <ttclass="file docutils literal"><spanclass="pre">doc/users</span></tt>,
<ttclass="file docutils literal"><spanclass="pre">doc/devel</span></tt>, <ttclass="file docutils literal"><spanclass="pre">doc/api</span></tt> and <ttclass="file docutils literal"><spanclass="pre">doc/faq</span></tt>. The main entry point is
<ttclass="file docutils literal"><spanclass="pre">doc/index.rst</span></tt>, which pulls in the <ttclass="file docutils literal"><spanclass="pre">index.rst</span></tt> file for the users
guide, developers guide, api reference, and faqs. The documentation suite is
built as a single document in order to make the most effective use of cross
referencing, we want to make navigating the Matplotlib documentation as easy as
possible.</p>
<p>Additional files can be added to the various guides by including their base
file name (the .rst extension is not necessary) in the table of contents.
It is also possible to include other documents through the use of an include
<h3>docstrings<aclass="headerlink" href="#docstrings" title="Permalink to this headline">¶</a></h3>
<p>In addition to the “narrative” documentation described above,
matplotlib also defines its API reference documentation in docstrings.
For the most part, these are standard Python docstrings, but
matplotlib also includes some features to better support documenting
getters and setters.</p>
<p>Matplotlib uses artist introspection of docstrings to support
properties. All properties that you want to support through <ttclass="docutils literal"><spanclass="pre">setp</span></tt>
and <ttclass="docutils literal"><spanclass="pre">getp</span></tt> should have a <ttclass="docutils literal"><spanclass="pre">set_property</span></tt> and <ttclass="docutils literal"><spanclass="pre">get_property</span></tt>
method in the <aclass="reference internal" href="../api/artist_api.html#matplotlib.artist.Artist" title="matplotlib.artist.Artist"><ttclass="xref py py-class docutils literal"><spanclass="pre">Artist</span></tt></a> class. Yes, this is
not ideal given python properties or enthought traits, but it is a
historical legacy for now. The setter methods use the docstring with
the ACCEPTS token to indicate the type of argument the method accepts.
e.g., in <aclass="reference internal" href="../api/lines_api.html#matplotlib.lines.Line2D" title="matplotlib.lines.Line2D"><ttclass="xref py py-class docutils literal"><spanclass="pre">matplotlib.lines.Line2D</span></tt></a>:</p>
<divclass="highlight-python"><divclass="highlight"><pre><spanclass="c"># in lines.py</span>
<p>Since matplotlib uses a lot of pass-through <ttclass="docutils literal"><spanclass="pre">kwargs</span></tt>, e.g., in every
function that creates a line (<aclass="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.plot" title="matplotlib.pyplot.plot"><ttclass="xref py py-func docutils literal"><spanclass="pre">plot()</span></tt></a>,
<aclass="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.semilogy" title="matplotlib.pyplot.semilogy"><ttclass="xref py py-func docutils literal"><spanclass="pre">semilogy()</span></tt></a>, etc...), it can be difficult for
the new user to know which <ttclass="docutils literal"><spanclass="pre">kwargs</span></tt> are supported. Matplotlib uses
a docstring interpolation scheme to support documentation of every
function that takes a <ttclass="docutils literal"><spanclass="pre">**kwargs</span></tt>. The requirements are:</p>
<olclass="arabic simple">
<li>single point of configuration so changes to the properties don’t
require multiple docstring edits.</li>
<li>as automated as possible so that as properties change, the docs
are updated automagically.</li>
</ol>
<p>The functions <ttclass="xref py py-attr docutils literal"><spanclass="pre">matplotlib.artist.kwdocd</span></tt> and
<aclass="reference internal" href="../api/artist_api.html#matplotlib.artist.kwdoc" title="matplotlib.artist.kwdoc"><ttclass="xref py py-func docutils literal"><spanclass="pre">matplotlib.artist.kwdoc()</span></tt></a> to facilitate this. They combine
python string interpolation in the docstring with the matplotlib
artist introspection facility that underlies <ttclass="docutils literal"><spanclass="pre">setp</span></tt> and <ttclass="docutils literal"><spanclass="pre">getp</span></tt>.
The <ttclass="docutils literal"><spanclass="pre">kwdocd</span></tt> is a single dictionary that maps class name to a
docstring of <ttclass="docutils literal"><spanclass="pre">kwargs</span></tt>. Here is an example from
<p>Then in any function accepting <aclass="reference internal" href="../api/lines_api.html#matplotlib.lines.Line2D" title="matplotlib.lines.Line2D"><ttclass="xref py py-class docutils literal"><spanclass="pre">Line2D</span></tt></a>
<p>Note there is a problem for <aclass="reference internal" href="../api/artist_api.html#matplotlib.artist.Artist" title="matplotlib.artist.Artist"><ttclass="xref py py-class docutils literal"><spanclass="pre">Artist</span></tt></a>
which supports <ttclass="docutils literal"><spanclass="pre">Patch</span></tt><ttclass="docutils literal"><spanclass="pre">kwargs</span></tt>, since the artist inspector cannot
work until the class is fully defined and we can’t modify the
<ttclass="docutils literal"><spanclass="pre">Patch.__init__.__doc__</span></tt> docstring outside the class definition.
There are some some manual hacks in this case, violating the
“single entry point” requirement above – see the
<spanid="formatting-mpl-docs"></span><h2>Formatting<aclass="headerlink" href="#formatting" title="Permalink to this headline">¶</a></h2>
<p>The Sphinx website contains plenty of <aclass="reference external" href="http://sphinx.pocoo.org/contents.html">documentation</a> concerning ReST markup and
working with Sphinx in general. Here are a few additional things to keep in mind:</p>
<ul>
<li><pclass="first">Please familiarize yourself with the Sphinx directives for <aclass="reference external" href="http://sphinx.pocoo.org/markup/inline.html">inline
markup</a>. Matplotlib’s documentation makes heavy use of cross-referencing and
other semantic markup. For example, when referring to external files, use the
<li><pclass="first">Footnotes <aclass="footnote-reference" href="#id3" id="id2">[1]</a> can be added using <ttclass="docutils literal"><spanclass="pre">[#]_</span></tt>, followed later by:</p>
<dt>A bit about <aclass="reference internal" href="#referring-to-mpl-docs"><em>Referring to mpl documents</em></a>:</dt>
<dd><pclass="first last">One more</p>
</dd>
</dl>
</div>
</li>
<li><pclass="first">Please keep the <aclass="reference internal" href="../glossary/index.html#glossary"><em>Glossary</em></a> in mind when writing documentation. You can
create a references to a term in the glossary with the <ttclass="docutils literal"><spanclass="pre">:term:</span></tt> role.</p>
</li>
<li><pclass="first">The autodoc extension will handle index entries for the API, but additional
entries in the <aclass="reference external" href="http://sphinx.pocoo.org/markup/para.html#index-generating-markup">index</a> need to be explicitly added.</p>
</li>
</ul>
<ul>
<li><pclass="first">Please limit the text width of docstrings to 70 characters.</p>
</li>
<li><pclass="first">Keyword arguments should be described using a definition list.</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">matplotlib makes extensive use of keyword arguments as pass-through
arguments, there are a many cases where a table is used in place of a
definition list for autogenerated sections of docstrings.</p>
</div>
</li>
</ul>
</div>
<divclass="section" id="figures">
<h2>Figures<aclass="headerlink" href="#figures" title="Permalink to this headline">¶</a></h2>
<h3>Dynamically generated figures<aclass="headerlink" href="#dynamically-generated-figures" title="Permalink to this headline">¶</a></h3>
<p>Figures can be automatically generated from scripts and included in
the docs. It is not necessary to explicitly save the figure in the
script, this will be done automatically at build time to ensure that
the code that is included runs and produces the advertised figure.</p>
<p>The path should be relative to the <ttclass="docutils literal"><spanclass="pre">doc</span></tt> directory. Any plots
specific to the documentation should be added to the <ttclass="docutils literal"><spanclass="pre">doc/pyplots</span></tt>
directory and committed to git. Plots from the <ttclass="docutils literal"><spanclass="pre">examples</span></tt> directory
may be referenced through the symlink <ttclass="docutils literal"><spanclass="pre">mpl_examples</span></tt> in the <ttclass="docutils literal"><spanclass="pre">doc</span></tt>
<spanid="plot-directive-documentation"></span><h4>Plot directive documentation<aclass="headerlink" href="#module-matplotlib.sphinxext.plot_directive" title="Permalink to this headline">¶</a></h4>
<p>A directive for including a matplotlib plot in a Sphinx document.</p>
<p>By default, in HTML output, <ttclass="xref py py-obj docutils literal"><spanclass="pre">plot</span></tt> will include a .png file with a
link to a high-res .png and .pdf. In LaTeX output, it will include a
.pdf.</p>
<p>The source code for the plot may be included in one of three ways:</p>
<blockquote>
<div><olclass="arabic">
<li><pclass="first"><strong>A path to a source file</strong> as the argument to the directive:</p>
<dd>If this source file is in a non-UTF8 or non-ASCII encoding,
the encoding must be specified using the <ttclass="xref py py-obj docutils literal"><spanclass="pre">:encoding:</span></tt> option.
The encoding will not be inferred using the <ttclass="docutils literal"><spanclass="pre">-*-</span><spanclass="pre">coding</span><spanclass="pre">-*-</span></tt>
metacomment.</dd>
<dt>context <spanclass="classifier-delimiter">:</span><spanclass="classifier">bool or str</span></dt>
<dd>If provided, the code will be run in the context of all
previous plot directives for which the <ttclass="xref py py-obj docutils literal"><spanclass="pre">:context:</span></tt> option was
specified. This only applies to inline code plot directives,
not those run from files. If the <ttclass="docutils literal"><spanclass="pre">:context:</span><spanclass="pre">reset</span></tt> is specified,
the context is reset for this and future plots.</dd>
<dd>If specified, the code block will be run, but no figures will
be inserted. This is usually useful with the <ttclass="docutils literal"><spanclass="pre">:context:</span></tt>
option.</dd>
</dl>
</div></blockquote>
<p>Additionally, this directive supports all of the options of the
<ttclass="xref py py-obj docutils literal"><spanclass="pre">image</span></tt> directive, except for <ttclass="xref py py-obj docutils literal"><spanclass="pre">target</span></tt> (since plot will add its own
target). These include <ttclass="xref py py-obj docutils literal"><spanclass="pre">alt</span></tt>, <ttclass="xref py py-obj docutils literal"><spanclass="pre">height</span></tt>, <ttclass="xref py py-obj docutils literal"><spanclass="pre">width</span></tt>, <ttclass="xref py py-obj docutils literal"><spanclass="pre">scale</span></tt>, <ttclass="xref py py-obj docutils literal"><spanclass="pre">align</span></tt> and
<h3>Examples<aclass="headerlink" href="#examples" title="Permalink to this headline">¶</a></h3>
<p>The source of the files in the <ttclass="docutils literal"><spanclass="pre">examples</span></tt> directory are
automatically included in the HTML docs. An image is generated and
included for all examples in the <ttclass="docutils literal"><spanclass="pre">api</span></tt> and <ttclass="docutils literal"><spanclass="pre">pylab_examples</span></tt>
directories. To exclude the example from having an image rendered,
insert the following special comment anywhere in the script:</p>
<h3>Animations<aclass="headerlink" href="#animations" title="Permalink to this headline">¶</a></h3>
<p>We have a matplotlib google/gmail account with username <ttclass="docutils literal"><spanclass="pre">mplgithub</span></tt>
which we used to setup the github account but can be used for other
purposes, like hosting google docs or youtube videos. You can embed a
matplotlib animation in the docs by first saving the animation as a
movie using <aclass="reference internal" href="../api/animation_api.html#matplotlib.animation.Animation.save" title="matplotlib.animation.Animation.save"><ttclass="xref py py-meth docutils literal"><spanclass="pre">matplotlib.animation.Animation.save()</span></tt></a>, and then
uploading to <aclass="reference external" href="http://www.youtube.com/user/matplotlib">matplotlib’s youtube
channel</a> and inserting the
embedding string youtube provides like:</p>
<divclass="highlight-python"><divclass="highlight"><pre>.. raw:: html
<spanid="referring-to-mpl-docs"></span><h2>Referring to mpl documents<aclass="headerlink" href="#referring-to-mpl-documents" title="Permalink to this headline">¶</a></h2>
<p>In the documentation, you may want to include to a document in the
matplotlib src, e.g., a license file or an image file from <ttclass="xref py py-obj docutils literal"><spanclass="pre">mpl-data</span></tt>,
refer to it via a relative path from the document where the rst file
resides, e.g., in <ttclass="file docutils literal"><spanclass="pre">users/navigation_toolbar.rst</span></tt>, we refer to the
<p>One exception to this is when referring to the examples dir. Relative
paths are extremely confusing in the sphinx plot extensions, so
without getting into the dirty details, it is easier to simply include
a symlink to the files at the top doc level directory. This way, API
documents like <aclass="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.plot" title="matplotlib.pyplot.plot"><ttclass="xref py py-meth docutils literal"><spanclass="pre">matplotlib.pyplot.plot()</span></tt></a> can refer to the
examples in a known location.</p>
<p>In the top level doc directory we have symlinks pointing to
the mpl <ttclass="xref py py-obj docutils literal"><spanclass="pre">examples</span></tt>:</p>
<divclass="highlight-python"><divclass="highlight"><pre>home:~/mpl/doc> ls -l mpl_*
mpl_examples -> ../examples
</pre></div>
</div>
<p>So we can include plots from the examples dir using the symlink:</p>
<spanid="internal-section-refs"></span><h2>Internal section references<aclass="headerlink" href="#internal-section-references" title="Permalink to this headline">¶</a></h2>
<p>To maximize internal consistency in section labeling and references,
use hyphen separated, descriptive labels for section references, e.g.,:</p>
<p>Keep in mind that we may want to reorganize the contents later, so
let’s avoid top level names in references like <ttclass="docutils literal"><spanclass="pre">user</span></tt> or <ttclass="docutils literal"><spanclass="pre">devel</span></tt>
or <ttclass="docutils literal"><spanclass="pre">faq</span></tt> unless necessary, because for example the FAQ “what is a
backend?” could later become part of the users guide, so the label:</p>
<p>In addition, since underscores are widely used by Sphinx itself, let’s prefer
hyphens to separate words.</p>
</div>
<divclass="section" id="section-names-etc">
<h2>Section names, etc<aclass="headerlink" href="#section-names-etc" title="Permalink to this headline">¶</a></h2>
<p>For everything but top level chapters, please use <ttclass="docutils literal"><spanclass="pre">Upper</span><spanclass="pre">lower</span></tt> for
section titles, e.g., <ttclass="docutils literal"><spanclass="pre">Possible</span><spanclass="pre">hangups</span></tt> rather than <ttclass="docutils literal"><spanclass="pre">Possible</span>
<spanclass="pre">Hangups</span></tt></p>
</div>
<divclass="section" id="inheritance-diagrams">
<h2>Inheritance diagrams<aclass="headerlink" href="#inheritance-diagrams" title="Permalink to this headline">¶</a></h2>
<p>Class inheritance diagrams can be generated with the
<ttclass="docutils literal"><spanclass="pre">inheritance-diagram</span></tt> directive. To use it, you provide the
directive with a number of class or module names (separated by
whitespace). If a module name is provided, all classes in that module
will be used. All of the ancestors of these classes will be included
in the inheritance diagram.</p>
<p>A single option is available: <em>parts</em> controls how many of parts in
the path to the class are shown. For example, if <em>parts</em> == 1, the
class <ttclass="docutils literal"><spanclass="pre">matplotlib.patches.Patch</span></tt> is shown as <ttclass="docutils literal"><spanclass="pre">Patch</span></tt>. If <em>parts</em>
== 2, it is shown as <ttclass="docutils literal"><spanclass="pre">patches.Patch</span></tt>. If <em>parts</em> == 0, the full
<areashape="rect" id="node1" href="../api/artist_api.html#matplotlib.artist.Artist" title="Abstract base class for someone who renders into a" alt="" coords="46,284,134,307"/>
<areashape="rect" id="node2" href="../api/lines_api.html#matplotlib.lines.Line2D" title="A line - the line can have both a solid linestyle connecting all" alt="" coords="227,237,320,261"/>
<areashape="rect" id="node7" href="../api/patches_api.html#matplotlib.patches.Patch" title="A patch is a 2D artist with a face color and an edge color." alt="" coords="221,284,326,307"/>
<areashape="rect" id="node25" href="../api/text_api.html#matplotlib.text.Text" title="Handle storing and drawing of text in window or data coordinates." alt="" coords="238,538,309,562"/>
<areashape="rect" id="node3" href="../api/lines_api.html#matplotlib.lines.VertexSelector" title="Manage the callbacks to maintain a list of selected vertices for" alt="" coords="20,237,161,261"/>
<areashape="rect" id="node4" href="../api/patches_api.html#matplotlib.patches.Arc" title="An elliptical arc.  Because it performs various optimizations, it" alt="" coords="630,5,723,29"/>
<areashape="rect" id="node14" href="../api/patches_api.html#matplotlib.patches.FancyArrowPatch" title="A fancy arrow patch. It draws an arrow using the :class:ArrowStyle." alt="" coords="371,167,545,191"/>
<areashape="rect" id="node17" href="../api/patches_api.html#matplotlib.patches.Polygon" title="A general polygon patch." alt="" coords="398,213,518,237"/>
<areashape="rect" id="node18" href="../api/patches_api.html#matplotlib.patches.FancyBboxPatch" title="Draw a fancy box around a rectangle with lower left at *xy*=(*x*," alt="" coords="373,260,543,284"/>
<areashape="rect" id="node19" href="../api/patches_api.html#matplotlib.patches.PathPatch" title="A general polycurve path patch." alt="" coords="392,306,524,330"/>
<areashape="rect" id="node20" href="../api/patches_api.html#matplotlib.patches.Rectangle" title="Draw a rectangle with lower left at *xy* = (*x*, *y*) with" alt="" coords="393,353,523,376"/>
<areashape="rect" id="node23" href="../api/patches_api.html#matplotlib.patches.YAArrow" title="Yet another arrow class." alt="" coords="398,492,518,516"/>
<areashape="rect" id="node8" href="../api/patches_api.html#matplotlib.patches.ArrowStyle" title=":class:`ArrowStyle` is a container class which defines several" alt="" coords="22,191,159,215"/>
<areashape="rect" id="node9" href="../api/patches_api.html#matplotlib.patches.BoxStyle" title=":class:`BoxStyle` is a container class which defines several" alt="" coords="28,144,153,168"/>
<areashape="rect" id="node11" href="../api/patches_api.html#matplotlib.patches.CirclePolygon" title="A polygon-approximation of a circle patch." alt="" coords="600,120,753,144"/>
<areashape="rect" id="node13" href="../api/patches_api.html#matplotlib.patches.ConnectionPatch" title="A :class:`~matplotlib.patches.ConnectionPatch` class is to make" alt="" coords="590,167,763,191"/>
<areashape="rect" id="node15" href="../api/patches_api.html#matplotlib.patches.ConnectionStyle" title=":class:`ConnectionStyle` is a container class which defines" alt="" coords="5,98,176,122"/>
<areashape="rect" id="node16" href="../api/patches_api.html#matplotlib.patches.FancyArrow" title="Like Arrow, but lets you set head width and head height independently." alt="" coords="606,213,747,237"/>
<areashape="rect" id="node24" href="../api/text_api.html#matplotlib.text.Annotation" title="A :class:`~matplotlib.text.Text` class to make annotating things" alt="" coords="401,538,515,562"/>
<areashape="rect" id="node27" href="../api/text_api.html#matplotlib.text.TextWithDash" title="This is basically a :class:`~matplotlib.text.Text` with a dash" alt="" coords="394,585,522,609"/>