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.1.3). For the latest version see <ahref="https://matplotlib.org/stable/tutorials/introductory/pyplot.html">https://matplotlib.org/stable/tutorials/introductory/pyplot.html</a></div>
<pclass="last">Click <aclass="reference internal" href="#sphx-glr-download-tutorials-introductory-pyplot-py"><spanclass="std std-ref">here</span></a> to download the full example code</p>
<spanid="sphx-glr-tutorials-introductory-pyplot-py"></span><h1>Pyplot tutorial<aclass="headerlink" href="#pyplot-tutorial" title="Permalink to this headline">¶</a></h1>
<p>An introduction to the pyplot interface.</p>
<divclass="section" id="intro-to-pyplot">
<h2>Intro to pyplot<aclass="headerlink" href="#intro-to-pyplot" title="Permalink to this headline">¶</a></h2>
<p><aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot" title="matplotlib.pyplot"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">matplotlib.pyplot</span></code></a> is a collection of command style functions
that make matplotlib work like MATLAB.
Each <codeclass="docutils literal notranslate"><spanclass="pre">pyplot</span></code> function makes
some change to a figure: e.g., creates a figure, creates a plotting area
in a figure, plots some lines in a plotting area, decorates the plot
with labels, etc.</p>
<p>In <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot" title="matplotlib.pyplot"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">matplotlib.pyplot</span></code></a> various states are preserved
across function calls, so that it keeps track of things like
the current figure and plotting area, and the plotting
functions are directed to the current axes (please note that "axes" here
and in most places in the documentation refers to the <em>axes</em>
<aclass="reference internal" href="usage.html#figure-parts"><spanclass="std std-ref">part of a figure</span></a>
and not the strict mathematical term for more than one axis).</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">the pyplot API is generally less-flexible than the object-oriented API.
Most of the function calls you see here can also be called as methods
from an <codeclass="docutils literal notranslate"><spanclass="pre">Axes</span></code> object. We recommend browsing the tutorials and
examples to see how this works.</p>
</div>
<p>Generating visualizations with pyplot is very quick:</p>
<ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">([</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="mi">2</span><spanclass="p">,</span><spanclass="mi">3</span><spanclass="p">,</span><spanclass="mi">4</span><spanclass="p">])</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.ylabel.html#matplotlib.pyplot.ylabel" title="View documentation for matplotlib.pyplot.ylabel"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">ylabel</span></a><spanclass="p">(</span><spanclass="s1">'some numbers'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="View documentation for matplotlib.pyplot.show"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">show</span></a><spanclass="p">()</span>
<p>You may be wondering why the x-axis ranges from 0-3 and the y-axis
from 1-4. If you provide a single list or array to the
<aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="matplotlib.pyplot.plot"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">plot()</span></code></a> command, matplotlib assumes it is a
sequence of y values, and automatically generates the x values for
you. Since python ranges start with 0, the default x vector has the
same length as y but starts with 0. Hence the x data are
<p><aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="matplotlib.pyplot.plot"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">plot()</span></code></a> is a versatile command, and will take
an arbitrary number of arguments. For example, to plot x versus y,
you can issue the command:</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">([</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="mi">2</span><spanclass="p">,</span><spanclass="mi">3</span><spanclass="p">,</span><spanclass="mi">4</span><spanclass="p">],</span><spanclass="p">[</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="mi">4</span><spanclass="p">,</span><spanclass="mi">9</span><spanclass="p">,</span><spanclass="mi">16</span><spanclass="p">])</span>
<h3>Formatting the style of your plot<aclass="headerlink" href="#formatting-the-style-of-your-plot" title="Permalink to this headline">¶</a></h3>
<p>For every x, y pair of arguments, there is an optional third argument
which is the format string that indicates the color and line type of
the plot. The letters and symbols of the format string are from
MATLAB, and you concatenate a color string with a line style string.
The default format string is 'b-', which is a solid blue line. For
example, to plot the above with red circles, you would issue</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">([</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="mi">2</span><spanclass="p">,</span><spanclass="mi">3</span><spanclass="p">,</span><spanclass="mi">4</span><spanclass="p">],</span><spanclass="p">[</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="mi">4</span><spanclass="p">,</span><spanclass="mi">9</span><spanclass="p">,</span><spanclass="mi">16</span><spanclass="p">],</span><spanclass="s1">'ro'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.axis.html#matplotlib.pyplot.axis" title="View documentation for matplotlib.pyplot.axis"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">axis</span></a><spanclass="p">([</span><spanclass="mi">0</span><spanclass="p">,</span><spanclass="mi">6</span><spanclass="p">,</span><spanclass="mi">0</span><spanclass="p">,</span><spanclass="mi">20</span><spanclass="p">])</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="View documentation for matplotlib.pyplot.show"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">show</span></a><spanclass="p">()</span>
<p>See the <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="matplotlib.pyplot.plot"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">plot()</span></code></a> documentation for a complete
list of line styles and format strings. The
<aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.axis.html#matplotlib.pyplot.axis" title="matplotlib.pyplot.axis"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">axis()</span></code></a> command in the example above takes a
list of <codeclass="docutils literal notranslate"><spanclass="pre">[xmin,</span><spanclass="pre">xmax,</span><spanclass="pre">ymin,</span><spanclass="pre">ymax]</span></code> and specifies the viewport of the
axes.</p>
<p>If matplotlib were limited to working with lists, it would be fairly
useless for numeric processing. Generally, you will use <aclass="reference external" href="http://www.numpy.org">numpy</a> arrays. In fact, all sequences are
converted to numpy arrays internally. The example below illustrates a
plotting several lines with different format styles in one command
<spanclass="c1"># evenly sampled time at 200ms intervals</span>
<ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="o">=</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html#numpy.arange" title="View documentation for numpy.arange"><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">arange</span></a><spanclass="p">(</span><spanclass="mf">0.</span><spanclass="p">,</span><spanclass="mf">5.</span><spanclass="p">,</span><spanclass="mf">0.2</span><spanclass="p">)</span>
<spanclass="c1"># red dashes, blue squares and green triangles</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="p">,</span><spanclass="s1">'r--'</span><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="o">**</span><spanclass="mi">2</span><spanclass="p">,</span><spanclass="s1">'bs'</span><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="o">**</span><spanclass="mi">3</span><spanclass="p">,</span><spanclass="s1">'g^'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="View documentation for matplotlib.pyplot.show"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">show</span></a><spanclass="p">()</span>
<spanid="plotting-with-keywords"></span><h2>Plotting with keyword strings<aclass="headerlink" href="#plotting-with-keyword-strings" title="Permalink to this headline">¶</a></h2>
<p>There are some instances where you have data in a format that lets you
access particular variables with strings. For example, with
<p>Matplotlib allows you provide such an object with
the <codeclass="docutils literal notranslate"><spanclass="pre">data</span></code> keyword argument. If provided, then you may generate plots with
the strings corresponding to these variables.</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><ahref="https://docs.python.org/3/library/stdtypes.html#dict" title="View documentation for builtins.dict"><spanclass="n">data</span></a><spanclass="o">=</span><spanclass="p">{</span><spanclass="s1">'a'</span><spanclass="p">:</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html#numpy.arange" title="View documentation for numpy.arange"><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">arange</span></a><spanclass="p">(</span><spanclass="mi">50</span><spanclass="p">),</span>
<ahref="https://docs.python.org/3/library/stdtypes.html#dict" title="View documentation for builtins.dict"><spanclass="n">data</span></a><spanclass="p">[</span><spanclass="s1">'b'</span><spanclass="p">]</span><spanclass="o">=</span><ahref="https://docs.python.org/3/library/stdtypes.html#dict" title="View documentation for builtins.dict"><spanclass="n">data</span></a><spanclass="p">[</span><spanclass="s1">'a'</span><spanclass="p">]</span><spanclass="o">+</span><spanclass="mi">10</span><spanclass="o">*</span><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">random</span><spanclass="o">.</span><spanclass="n">randn</span><spanclass="p">(</span><spanclass="mi">50</span><spanclass="p">)</span>
<ahref="https://docs.python.org/3/library/stdtypes.html#dict" title="View documentation for builtins.dict"><spanclass="n">data</span></a><spanclass="p">[</span><spanclass="s1">'d'</span><spanclass="p">]</span><spanclass="o">=</span><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">abs</span><spanclass="p">(</span><ahref="https://docs.python.org/3/library/stdtypes.html#dict" title="View documentation for builtins.dict"><spanclass="n">data</span></a><spanclass="p">[</span><spanclass="s1">'d'</span><spanclass="p">])</span><spanclass="o">*</span><spanclass="mi">100</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.scatter.html#matplotlib.pyplot.scatter" title="View documentation for matplotlib.pyplot.scatter"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">scatter</span></a><spanclass="p">(</span><spanclass="s1">'a'</span><spanclass="p">,</span><spanclass="s1">'b'</span><spanclass="p">,</span><spanclass="n">c</span><spanclass="o">=</span><spanclass="s1">'c'</span><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">s</span></a><spanclass="o">=</span><spanclass="s1">'d'</span><spanclass="p">,</span><ahref="https://docs.python.org/3/library/stdtypes.html#dict" title="View documentation for builtins.dict"><spanclass="n">data</span></a><spanclass="o">=</span><ahref="https://docs.python.org/3/library/stdtypes.html#dict" title="View documentation for builtins.dict"><spanclass="n">data</span></a><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.xlabel.html#matplotlib.pyplot.xlabel" title="View documentation for matplotlib.pyplot.xlabel"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">xlabel</span></a><spanclass="p">(</span><spanclass="s1">'entry a'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.ylabel.html#matplotlib.pyplot.ylabel" title="View documentation for matplotlib.pyplot.ylabel"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">ylabel</span></a><spanclass="p">(</span><spanclass="s1">'entry b'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="View documentation for matplotlib.pyplot.show"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">show</span></a><spanclass="p">()</span>
<spanid="plotting-with-categorical-vars"></span><h2>Plotting with categorical variables<aclass="headerlink" href="#plotting-with-categorical-variables" title="Permalink to this headline">¶</a></h2>
<p>It is also possible to create a plot using categorical variables.
Matplotlib allows you to pass categorical variables directly to
many plotting functions. For example:</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><ahref="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><spanclass="n">names</span></a><spanclass="o">=</span><spanclass="p">[</span><spanclass="s1">'group_a'</span><spanclass="p">,</span><spanclass="s1">'group_b'</span><spanclass="p">,</span><spanclass="s1">'group_c'</span><spanclass="p">]</span>
<ahref="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><spanclass="n">values</span></a><spanclass="o">=</span><spanclass="p">[</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="mi">10</span><spanclass="p">,</span><spanclass="mi">100</span><spanclass="p">]</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.figure.html#matplotlib.pyplot.figure" title="View documentation for matplotlib.pyplot.figure"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">figure</span></a><spanclass="p">(</span><spanclass="n">figsize</span><spanclass="o">=</span><spanclass="p">(</span><spanclass="mi">9</span><spanclass="p">,</span><spanclass="mi">3</span><spanclass="p">))</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot" title="View documentation for matplotlib.pyplot.subplot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplot</span></a><spanclass="p">(</span><spanclass="mi">131</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.bar.html#matplotlib.pyplot.bar" title="View documentation for matplotlib.pyplot.bar"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">bar</span></a><spanclass="p">(</span><ahref="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><spanclass="n">names</span></a><spanclass="p">,</span><ahref="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><spanclass="n">values</span></a><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot" title="View documentation for matplotlib.pyplot.subplot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplot</span></a><spanclass="p">(</span><spanclass="mi">132</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.scatter.html#matplotlib.pyplot.scatter" title="View documentation for matplotlib.pyplot.scatter"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">scatter</span></a><spanclass="p">(</span><ahref="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><spanclass="n">names</span></a><spanclass="p">,</span><ahref="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><spanclass="n">values</span></a><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot" title="View documentation for matplotlib.pyplot.subplot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplot</span></a><spanclass="p">(</span><spanclass="mi">133</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">(</span><ahref="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><spanclass="n">names</span></a><spanclass="p">,</span><ahref="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><spanclass="n">values</span></a><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.suptitle.html#matplotlib.pyplot.suptitle" title="View documentation for matplotlib.pyplot.suptitle"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">suptitle</span></a><spanclass="p">(</span><spanclass="s1">'Categorical Plotting'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="View documentation for matplotlib.pyplot.show"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">show</span></a><spanclass="p">()</span>
<spanid="id1"></span><h2>Controlling line properties<aclass="headerlink" href="#controlling-line-properties" title="Permalink to this headline">¶</a></h2>
<p>Lines have many attributes that you can set: linewidth, dash style,
antialiased, etc; see <aclass="reference internal" href="../../api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D" title="matplotlib.lines.Line2D"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">matplotlib.lines.Line2D</span></code></a>. There are
several ways to set line properties</p>
<ul>
<li><pclass="first">Use keyword args:</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">x</span></a><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">y</span></a><spanclass="p">,</span><spanclass="n">linewidth</span><spanclass="o">=</span><spanclass="mf">2.0</span><spanclass="p">)</span>
</pre></div>
</div>
</li>
<li><pclass="first">Use the setter methods of a <codeclass="docutils literal notranslate"><spanclass="pre">Line2D</span></code> instance. <codeclass="docutils literal notranslate"><spanclass="pre">plot</span></code> returns a list
of <codeclass="docutils literal notranslate"><spanclass="pre">Line2D</span></code> objects; e.g., <codeclass="docutils literal notranslate"><spanclass="pre">line1,</span><spanclass="pre">line2</span><spanclass="pre">=</span><spanclass="pre">plot(x1,</span><spanclass="pre">y1,</span><spanclass="pre">x2,</span><spanclass="pre">y2)</span></code>. In the code
below we will suppose that we have only
one line so that the list returned is of length 1. We use tuple unpacking with
<codeclass="docutils literal notranslate"><spanclass="pre">line,</span></code> to get the first element of that list:</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><ahref="../../api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D" title="View documentation for matplotlib.lines.Line2D"><spanclass="n">line</span></a><spanclass="p">,</span><spanclass="o">=</span><ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">x</span></a><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">y</span></a><spanclass="p">,</span><spanclass="s1">'-'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D" title="View documentation for matplotlib.lines.Line2D"><spanclass="n">line</span></a><spanclass="o">.</span><spanclass="n">set_antialiased</span><spanclass="p">(</span><spanclass="kc">False</span><spanclass="p">)</span><spanclass="c1"># turn off antialiasing</span>
</pre></div>
</div>
</li>
<li><pclass="first">Use the <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.setp.html#matplotlib.pyplot.setp" title="matplotlib.pyplot.setp"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">setp()</span></code></a> command. The example below
uses a MATLAB-style command to set multiple properties
on a list of lines. <codeclass="docutils literal notranslate"><spanclass="pre">setp</span></code> works transparently with a list of objects
or a single object. You can either use python keyword arguments or
MATLAB-style string/value pairs:</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="n">lines</span><spanclass="o">=</span><ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">(</span><spanclass="n">x1</span><spanclass="p">,</span><spanclass="n">y1</span><spanclass="p">,</span><spanclass="n">x2</span><spanclass="p">,</span><spanclass="n">y2</span><spanclass="p">)</span>
<p>Here are the available <aclass="reference internal" href="../../api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D" title="matplotlib.lines.Line2D"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Line2D</span></code></a> properties.</p>
<tableborder="1" class="docutils">
<colgroup>
<colwidth="24%" />
<colwidth="76%" />
</colgroup>
<theadvalign="bottom">
<trclass="row-odd"><thclass="head">Property</th>
<thclass="head">Value Type</th>
</tr>
</thead>
<tbodyvalign="top">
<trclass="row-even"><td>alpha</td>
<td>float</td>
</tr>
<trclass="row-odd"><td>animated</td>
<td>[True | False]</td>
</tr>
<trclass="row-even"><td>antialiased or aa</td>
<td>[True | False]</td>
</tr>
<trclass="row-odd"><td>clip_box</td>
<td>a matplotlib.transform.Bbox instance</td>
</tr>
<trclass="row-even"><td>clip_on</td>
<td>[True | False]</td>
</tr>
<trclass="row-odd"><td>clip_path</td>
<td>a Path instance and a Transform instance, a Patch</td>
<p>To get a list of settable line properties, call the
<aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.setp.html#matplotlib.pyplot.setp" title="matplotlib.pyplot.setp"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">setp()</span></code></a> function with a line or lines
as argument</p>
<divclass="highlight-ipython notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">In [69]: </span><spanclass="n">lines</span><spanclass="o">=</span><ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">([</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="mi">2</span><spanclass="p">,</span><spanclass="mi">3</span><spanclass="p">])</span>
<spanid="multiple-figs-axes"></span><h2>Working with multiple figures and axes<aclass="headerlink" href="#working-with-multiple-figures-and-axes" title="Permalink to this headline">¶</a></h2>
<p>MATLAB, and <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot" title="matplotlib.pyplot"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">pyplot</span></code></a>, have the concept of the current
figure and the current axes. All plotting commands apply to the
current axes. The function <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.gca.html#matplotlib.pyplot.gca" title="matplotlib.pyplot.gca"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">gca()</span></code></a> returns the
current axes (a <aclass="reference internal" href="../../api/axes_api.html#matplotlib.axes.Axes" title="matplotlib.axes.Axes"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">matplotlib.axes.Axes</span></code></a> instance), and
<aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.gcf.html#matplotlib.pyplot.gcf" title="matplotlib.pyplot.gcf"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">gcf()</span></code></a> returns the current figure
(<aclass="reference internal" href="../../api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure" title="matplotlib.figure.Figure"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">matplotlib.figure.Figure</span></code></a> instance). Normally, you don't have
to worry about this, because it is all taken care of behind the
scenes. Below is a script to create two subplots.</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="k">def</span><spanclass="nf">f</span><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="p">):</span>
<spanclass="k">return</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.exp.html#numpy.exp" title="View documentation for numpy.exp"><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">exp</span></a><spanclass="p">(</span><spanclass="o">-</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="p">)</span><spanclass="o">*</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.cos.html#numpy.cos" title="View documentation for numpy.cos"><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">cos</span></a><spanclass="p">(</span><spanclass="mi">2</span><spanclass="o">*</span><ahref="https://docs.scipy.org/doc/numpy/reference/constants.html#numpy.pi" title="View documentation for numpy.pi"><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">pi</span></a><spanclass="o">*</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="p">)</span>
<ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t1</span></a><spanclass="o">=</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html#numpy.arange" title="View documentation for numpy.arange"><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">arange</span></a><spanclass="p">(</span><spanclass="mf">0.0</span><spanclass="p">,</span><spanclass="mf">5.0</span><spanclass="p">,</span><spanclass="mf">0.1</span><spanclass="p">)</span>
<ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t2</span></a><spanclass="o">=</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html#numpy.arange" title="View documentation for numpy.arange"><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">arange</span></a><spanclass="p">(</span><spanclass="mf">0.0</span><spanclass="p">,</span><spanclass="mf">5.0</span><spanclass="p">,</span><spanclass="mf">0.02</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.figure.html#matplotlib.pyplot.figure" title="View documentation for matplotlib.pyplot.figure"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">figure</span></a><spanclass="p">()</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot" title="View documentation for matplotlib.pyplot.subplot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplot</span></a><spanclass="p">(</span><spanclass="mi">211</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t1</span></a><spanclass="p">,</span><ahref="https://docs.python.org/3/library/functions.html#object" title="View documentation for builtins.object"><spanclass="n">f</span></a><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t1</span></a><spanclass="p">),</span><spanclass="s1">'bo'</span><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t2</span></a><spanclass="p">,</span><ahref="https://docs.python.org/3/library/functions.html#object" title="View documentation for builtins.object"><spanclass="n">f</span></a><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t2</span></a><spanclass="p">),</span><spanclass="s1">'k'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot" title="View documentation for matplotlib.pyplot.subplot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplot</span></a><spanclass="p">(</span><spanclass="mi">212</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t2</span></a><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.cos.html#numpy.cos" title="View documentation for numpy.cos"><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">cos</span></a><spanclass="p">(</span><spanclass="mi">2</span><spanclass="o">*</span><ahref="https://docs.scipy.org/doc/numpy/reference/constants.html#numpy.pi" title="View documentation for numpy.pi"><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">pi</span></a><spanclass="o">*</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t2</span></a><spanclass="p">),</span><spanclass="s1">'r--'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="View documentation for matplotlib.pyplot.show"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">show</span></a><spanclass="p">()</span>
<p>The <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.figure.html#matplotlib.pyplot.figure" title="matplotlib.pyplot.figure"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">figure()</span></code></a> command here is optional because
<codeclass="docutils literal notranslate"><spanclass="pre">figure(1)</span></code> will be created by default, just as a <codeclass="docutils literal notranslate"><spanclass="pre">subplot(111)</span></code>
will be created by default if you don't manually specify any axes. The
<spanclass="pre">numcols,</span><spanclass="pre">plot_number</span></code> where <codeclass="docutils literal notranslate"><spanclass="pre">plot_number</span></code> ranges from 1 to
<codeclass="docutils literal notranslate"><spanclass="pre">numrows*numcols</span></code>. The commas in the <codeclass="docutils literal notranslate"><spanclass="pre">subplot</span></code> command are
optional if <codeclass="docutils literal notranslate"><spanclass="pre">numrows*numcols<10</span></code>. So <codeclass="docutils literal notranslate"><spanclass="pre">subplot(211)</span></code> is identical
to <codeclass="docutils literal notranslate"><spanclass="pre">subplot(2,</span><spanclass="pre">1,</span><spanclass="pre">1)</span></code>.</p>
<p>You can create an arbitrary number of subplots
and axes. If you want to place an axes manually, i.e., not on a
rectangular grid, use the <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.axes.html#matplotlib.pyplot.axes" title="matplotlib.pyplot.axes"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">axes()</span></code></a> command,
which allows you to specify the location as <codeclass="docutils literal notranslate"><spanclass="pre">axes([left,</span><spanclass="pre">bottom,</span>
<spanclass="pre">width,</span><spanclass="pre">height])</span></code> where all values are in fractional (0 to 1)
coordinates. See <aclass="reference internal" href="../../gallery/subplots_axes_and_figures/axes_demo.html"><spanclass="doc">Axes Demo</span></a> for an example of
placing axes manually and <aclass="reference internal" href="../../gallery/subplots_axes_and_figures/subplot_demo.html"><spanclass="doc">Basic Subplot Demo</span></a> for an
example with lots of subplots.</p>
<p>You can create multiple figures by using multiple
<aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.figure.html#matplotlib.pyplot.figure" title="matplotlib.pyplot.figure"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">figure()</span></code></a> calls with an increasing figure
number. Of course, each figure can contain as many axes and subplots
<ahref="../../api/_as_gen/matplotlib.pyplot.figure.html#matplotlib.pyplot.figure" title="View documentation for matplotlib.pyplot.figure"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">figure</span></a><spanclass="p">(</span><spanclass="mi">1</span><spanclass="p">)</span><spanclass="c1"># the first figure</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot" title="View documentation for matplotlib.pyplot.subplot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplot</span></a><spanclass="p">(</span><spanclass="mi">211</span><spanclass="p">)</span><spanclass="c1"># the first subplot in the first figure</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">([</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="mi">2</span><spanclass="p">,</span><spanclass="mi">3</span><spanclass="p">])</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot" title="View documentation for matplotlib.pyplot.subplot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplot</span></a><spanclass="p">(</span><spanclass="mi">212</span><spanclass="p">)</span><spanclass="c1"># the second subplot in the first figure</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">([</span><spanclass="mi">4</span><spanclass="p">,</span><spanclass="mi">5</span><spanclass="p">,</span><spanclass="mi">6</span><spanclass="p">])</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.figure.html#matplotlib.pyplot.figure" title="View documentation for matplotlib.pyplot.figure"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">figure</span></a><spanclass="p">(</span><spanclass="mi">2</span><spanclass="p">)</span><spanclass="c1"># a second figure</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">([</span><spanclass="mi">4</span><spanclass="p">,</span><spanclass="mi">5</span><spanclass="p">,</span><spanclass="mi">6</span><spanclass="p">])</span><spanclass="c1"># creates a subplot(111) by default</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.figure.html#matplotlib.pyplot.figure" title="View documentation for matplotlib.pyplot.figure"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">figure</span></a><spanclass="p">(</span><spanclass="mi">1</span><spanclass="p">)</span><spanclass="c1"># figure 1 current; subplot(212) still current</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot" title="View documentation for matplotlib.pyplot.subplot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplot</span></a><spanclass="p">(</span><spanclass="mi">211</span><spanclass="p">)</span><spanclass="c1"># make subplot(211) in figure1 current</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.title.html#matplotlib.pyplot.title" title="View documentation for matplotlib.pyplot.title"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">title</span></a><spanclass="p">(</span><spanclass="s1">'Easy as 1, 2, 3'</span><spanclass="p">)</span><spanclass="c1"># subplot 211 title</span>
</pre></div>
</div>
<p>You can clear the current figure with <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.clf.html#matplotlib.pyplot.clf" title="matplotlib.pyplot.clf"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">clf()</span></code></a>
and the current axes with <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.cla.html#matplotlib.pyplot.cla" title="matplotlib.pyplot.cla"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">cla()</span></code></a>. If you find
it annoying that states (specifically the current image, figure and axes)
are being maintained for you behind the scenes, don't despair: this is just a thin
stateful wrapper around an object oriented API, which you can use
instead (see <aclass="reference internal" href="../intermediate/artists.html"><spanclass="doc">Artist tutorial</span></a>)</p>
<p>If you are making lots of figures, you need to be aware of one
more thing: the memory required for a figure is not completely
released until the figure is explicitly closed with
<aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.close.html#matplotlib.pyplot.close" title="matplotlib.pyplot.close"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">close()</span></code></a>. Deleting all references to the
figure, and/or using the window manager to kill the window in which
the figure appears on the screen, is not enough, because pyplot
<spanid="id2"></span><h2>Working with text<aclass="headerlink" href="#working-with-text" title="Permalink to this headline">¶</a></h2>
<p>The <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> command can be used to add text in
an arbitrary location, and the <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.xlabel.html#matplotlib.pyplot.xlabel" title="matplotlib.pyplot.xlabel"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">xlabel()</span></code></a>,
are used to add text in the indicated locations (see <aclass="reference internal" href="../text/text_intro.html"><spanclass="doc">Text in Matplotlib Plots</span></a>
for a more detailed example)</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><ahref="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><spanclass="n">mu</span></a><spanclass="p">,</span><ahref="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><spanclass="n">sigma</span></a><spanclass="o">=</span><spanclass="mi">100</span><spanclass="p">,</span><spanclass="mi">15</span>
<ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">x</span></a><spanclass="o">=</span><ahref="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><spanclass="n">mu</span></a><spanclass="o">+</span><ahref="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><spanclass="n">sigma</span></a><spanclass="o">*</span><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">random</span><spanclass="o">.</span><spanclass="n">randn</span><spanclass="p">(</span><spanclass="mi">10000</span><spanclass="p">)</span>
<spanclass="c1"># the histogram of the data</span>
<ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">n</span></a><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">bins</span></a><spanclass="p">,</span><ahref="../../api/cbook_api.html#matplotlib.cbook.silent_list" title="View documentation for matplotlib.cbook.silent_list"><spanclass="n">patches</span></a><spanclass="o">=</span><ahref="../../api/_as_gen/matplotlib.pyplot.hist.html#matplotlib.pyplot.hist" title="View documentation for matplotlib.pyplot.hist"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">hist</span></a><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">x</span></a><spanclass="p">,</span><spanclass="mi">50</span><spanclass="p">,</span><spanclass="n">density</span><spanclass="o">=</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="n">facecolor</span><spanclass="o">=</span><spanclass="s1">'g'</span><spanclass="p">,</span><spanclass="n">alpha</span><spanclass="o">=</span><spanclass="mf">0.75</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.xlabel.html#matplotlib.pyplot.xlabel" title="View documentation for matplotlib.pyplot.xlabel"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">xlabel</span></a><spanclass="p">(</span><spanclass="s1">'Smarts'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.ylabel.html#matplotlib.pyplot.ylabel" title="View documentation for matplotlib.pyplot.ylabel"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">ylabel</span></a><spanclass="p">(</span><spanclass="s1">'Probability'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.title.html#matplotlib.pyplot.title" title="View documentation for matplotlib.pyplot.title"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">title</span></a><spanclass="p">(</span><spanclass="s1">'Histogram of IQ'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.text.html#matplotlib.pyplot.text" title="View documentation for matplotlib.pyplot.text"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">text</span></a><spanclass="p">(</span><spanclass="mi">60</span><spanclass="p">,</span><spanclass="o">.</span><spanclass="mi">025</span><spanclass="p">,</span><spanclass="sa">r</span><spanclass="s1">'$\mu=100,\ \sigma=15$'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.axis.html#matplotlib.pyplot.axis" title="View documentation for matplotlib.pyplot.axis"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">axis</span></a><spanclass="p">([</span><spanclass="mi">40</span><spanclass="p">,</span><spanclass="mi">160</span><spanclass="p">,</span><spanclass="mi">0</span><spanclass="p">,</span><spanclass="mf">0.03</span><spanclass="p">])</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.grid.html#matplotlib.pyplot.grid" title="View documentation for matplotlib.pyplot.grid"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">grid</span></a><spanclass="p">(</span><spanclass="kc">True</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="View documentation for matplotlib.pyplot.show"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">show</span></a><spanclass="p">()</span>
<p>All of the <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> commands return an
<aclass="reference internal" href="../../api/text_api.html#matplotlib.text.Text" title="matplotlib.text.Text"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">matplotlib.text.Text</span></code></a> instance. Just as with with lines
above, you can customize the properties by passing keyword arguments
into the text functions or using <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.setp.html#matplotlib.pyplot.setp" title="matplotlib.pyplot.setp"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">setp()</span></code></a>:</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="o">=</span><ahref="../../api/_as_gen/matplotlib.pyplot.xlabel.html#matplotlib.pyplot.xlabel" title="View documentation for matplotlib.pyplot.xlabel"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">xlabel</span></a><spanclass="p">(</span><spanclass="s1">'my data'</span><spanclass="p">,</span><spanclass="n">fontsize</span><spanclass="o">=</span><spanclass="mi">14</span><spanclass="p">,</span><spanclass="n">color</span><spanclass="o">=</span><spanclass="s1">'red'</span><spanclass="p">)</span>
</pre></div>
</div>
<p>These properties are covered in more detail in <aclass="reference internal" href="../text/text_props.html"><spanclass="doc">Text properties and layout</span></a>.</p>
<h3>Using mathematical expressions in text<aclass="headerlink" href="#using-mathematical-expressions-in-text" title="Permalink to this headline">¶</a></h3>
<p>matplotlib accepts TeX equation expressions in any text expression.
For example to write the expression <spanclass="math notranslate nohighlight">\(\sigma_i=15\)</span> in the title,
you can write a TeX expression surrounded by dollar signs:</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><ahref="../../api/_as_gen/matplotlib.pyplot.title.html#matplotlib.pyplot.title" title="View documentation for matplotlib.pyplot.title"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">title</span></a><spanclass="p">(</span><spanclass="sa">r</span><spanclass="s1">'$\sigma_i=15$'</span><spanclass="p">)</span>
</pre></div>
</div>
<p>The <codeclass="docutils literal notranslate"><spanclass="pre">r</span></code> preceding the title string is important -- it signifies
that the string is a <em>raw</em> string and not to treat backslashes as
python escapes. matplotlib has a built-in TeX expression parser and
layout engine, and ships its own math fonts -- for details see
<aclass="reference internal" href="../text/mathtext.html"><spanclass="doc">Writing mathematical expressions</span></a>. Thus you can use mathematical text across platforms
without requiring a TeX installation. For those who have LaTeX and
dvipng installed, you can also use LaTeX to format your text and
incorporate the output directly into your display figures or saved
postscript -- see <aclass="reference internal" href="../text/usetex.html"><spanclass="doc">Text rendering With LaTeX</span></a>.</p>
</div>
<divclass="section" id="annotating-text">
<h3>Annotating text<aclass="headerlink" href="#annotating-text" title="Permalink to this headline">¶</a></h3>
<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> command above
place text at an arbitrary position on the Axes. A common use for
text is to annotate some feature of the plot, and the
functionality to make annotations easy. In an annotation, there are
two points to consider: the location being annotated represented by
the argument <codeclass="docutils literal notranslate"><spanclass="pre">xy</span></code> and the location of the text <codeclass="docutils literal notranslate"><spanclass="pre">xytext</span></code>. Both of
these arguments are <codeclass="docutils literal notranslate"><spanclass="pre">(x,y)</span></code> tuples.</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><ahref="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><spanclass="n">ax</span></a><spanclass="o">=</span><ahref="../../api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot" title="View documentation for matplotlib.pyplot.subplot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplot</span></a><spanclass="p">(</span><spanclass="mi">111</span><spanclass="p">)</span>
<ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="o">=</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html#numpy.arange" title="View documentation for numpy.arange"><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">arange</span></a><spanclass="p">(</span><spanclass="mf">0.0</span><spanclass="p">,</span><spanclass="mf">5.0</span><spanclass="p">,</span><spanclass="mf">0.01</span><spanclass="p">)</span>
<ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">s</span></a><spanclass="o">=</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.cos.html#numpy.cos" title="View documentation for numpy.cos"><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">cos</span></a><spanclass="p">(</span><spanclass="mi">2</span><spanclass="o">*</span><ahref="https://docs.scipy.org/doc/numpy/reference/constants.html#numpy.pi" title="View documentation for numpy.pi"><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">pi</span></a><spanclass="o">*</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D" title="View documentation for matplotlib.lines.Line2D"><spanclass="n">line</span></a><spanclass="p">,</span><spanclass="o">=</span><ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">t</span></a><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">s</span></a><spanclass="p">,</span><spanclass="n">lw</span><spanclass="o">=</span><spanclass="mi">2</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.annotate.html#matplotlib.pyplot.annotate" title="View documentation for matplotlib.pyplot.annotate"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">annotate</span></a><spanclass="p">(</span><spanclass="s1">'local max'</span><spanclass="p">,</span><spanclass="n">xy</span><spanclass="o">=</span><spanclass="p">(</span><spanclass="mi">2</span><spanclass="p">,</span><spanclass="mi">1</span><spanclass="p">),</span><spanclass="n">xytext</span><spanclass="o">=</span><spanclass="p">(</span><spanclass="mi">3</span><spanclass="p">,</span><spanclass="mf">1.5</span><spanclass="p">),</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.ylim.html#matplotlib.pyplot.ylim" title="View documentation for matplotlib.pyplot.ylim"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">ylim</span></a><spanclass="p">(</span><spanclass="o">-</span><spanclass="mi">2</span><spanclass="p">,</span><spanclass="mi">2</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="View documentation for matplotlib.pyplot.show"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">show</span></a><spanclass="p">()</span>
<p>In this basic example, both the <codeclass="docutils literal notranslate"><spanclass="pre">xy</span></code> (arrow tip) and <codeclass="docutils literal notranslate"><spanclass="pre">xytext</span></code>
locations (text location) are in data coordinates. There are a
variety of other coordinate systems one can choose -- see
<aclass="reference internal" href="../text/annotations.html#annotations-tutorial"><spanclass="std std-ref">Basic annotation</span></a> and <aclass="reference internal" href="../text/annotations.html#plotting-guide-annotation"><spanclass="std std-ref">Advanced Annotation</span></a> for
<h2>Logarithmic and other nonlinear axes<aclass="headerlink" href="#logarithmic-and-other-nonlinear-axes" title="Permalink to this headline">¶</a></h2>
<p><aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot" title="matplotlib.pyplot"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">matplotlib.pyplot</span></code></a> supports not only linear axis scales, but also
logarithmic and logit scales. This is commonly used if data spans many orders
of magnitude. Changing the scale of an axis is easy:</p>
<blockquote>
<div>plt.xscale('log')</div></blockquote>
<p>An example of four plots with the same data and different scales for the y axis
is shown below.</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="kn">from</span><spanclass="nn">matplotlib.ticker</span><spanclass="kn">import</span><ahref="../../api/ticker_api.html#matplotlib.ticker.NullFormatter" title="View documentation for matplotlib.ticker.NullFormatter"><spanclass="n">NullFormatter</span></a><spanclass="c1"># useful for `logit` scale</span>
<spanclass="c1"># Fixing random state for reproducibility</span>
<spanclass="c1"># make up some data in the interval ]0, 1[</span>
<ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">y</span></a><spanclass="o">=</span><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">random</span><spanclass="o">.</span><spanclass="n">normal</span><spanclass="p">(</span><spanclass="n">loc</span><spanclass="o">=</span><spanclass="mf">0.5</span><spanclass="p">,</span><spanclass="n">scale</span><spanclass="o">=</span><spanclass="mf">0.4</span><spanclass="p">,</span><spanclass="n">size</span><spanclass="o">=</span><spanclass="mi">1000</span><spanclass="p">)</span>
<ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">y</span></a><spanclass="o">=</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">y</span></a><spanclass="p">[(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">y</span></a><spanclass="o">></span><spanclass="mi">0</span><spanclass="p">)</span><spanclass="o">&</span><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">y</span></a><spanclass="o"><</span><spanclass="mi">1</span><spanclass="p">)]</span>
<ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.sort.html#numpy.ndarray.sort" title="View documentation for numpy.ndarray.sort"><spanclass="n">y</span><spanclass="o">.</span><spanclass="n">sort</span></a><spanclass="p">()</span>
<ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">x</span></a><spanclass="o">=</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html#numpy.arange" title="View documentation for numpy.arange"><spanclass="n">np</span><spanclass="o">.</span><spanclass="n">arange</span></a><spanclass="p">(</span><spanclass="nb">len</span><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">y</span></a><spanclass="p">))</span>
<spanclass="c1"># plot with various axes scales</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.figure.html#matplotlib.pyplot.figure" title="View documentation for matplotlib.pyplot.figure"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">figure</span></a><spanclass="p">()</span>
<spanclass="c1"># linear</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot" title="View documentation for matplotlib.pyplot.subplot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplot</span></a><spanclass="p">(</span><spanclass="mi">221</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">x</span></a><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">y</span></a><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.yscale.html#matplotlib.pyplot.yscale" title="View documentation for matplotlib.pyplot.yscale"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">yscale</span></a><spanclass="p">(</span><spanclass="s1">'linear'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.title.html#matplotlib.pyplot.title" title="View documentation for matplotlib.pyplot.title"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">title</span></a><spanclass="p">(</span><spanclass="s1">'linear'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.grid.html#matplotlib.pyplot.grid" title="View documentation for matplotlib.pyplot.grid"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">grid</span></a><spanclass="p">(</span><spanclass="kc">True</span><spanclass="p">)</span>
<spanclass="c1"># log</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot" title="View documentation for matplotlib.pyplot.subplot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplot</span></a><spanclass="p">(</span><spanclass="mi">222</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">x</span></a><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">y</span></a><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.yscale.html#matplotlib.pyplot.yscale" title="View documentation for matplotlib.pyplot.yscale"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">yscale</span></a><spanclass="p">(</span><spanclass="s1">'log'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.title.html#matplotlib.pyplot.title" title="View documentation for matplotlib.pyplot.title"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">title</span></a><spanclass="p">(</span><spanclass="s1">'log'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.grid.html#matplotlib.pyplot.grid" title="View documentation for matplotlib.pyplot.grid"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">grid</span></a><spanclass="p">(</span><spanclass="kc">True</span><spanclass="p">)</span>
<spanclass="c1"># symmetric log</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot" title="View documentation for matplotlib.pyplot.subplot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplot</span></a><spanclass="p">(</span><spanclass="mi">223</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">x</span></a><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">y</span></a><spanclass="o">-</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.mean.html#numpy.ndarray.mean" title="View documentation for numpy.ndarray.mean"><spanclass="n">y</span><spanclass="o">.</span><spanclass="n">mean</span></a><spanclass="p">())</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.yscale.html#matplotlib.pyplot.yscale" title="View documentation for matplotlib.pyplot.yscale"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">yscale</span></a><spanclass="p">(</span><spanclass="s1">'symlog'</span><spanclass="p">,</span><spanclass="n">linthreshy</span><spanclass="o">=</span><spanclass="mf">0.01</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.title.html#matplotlib.pyplot.title" title="View documentation for matplotlib.pyplot.title"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">title</span></a><spanclass="p">(</span><spanclass="s1">'symlog'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.grid.html#matplotlib.pyplot.grid" title="View documentation for matplotlib.pyplot.grid"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">grid</span></a><spanclass="p">(</span><spanclass="kc">True</span><spanclass="p">)</span>
<spanclass="c1"># logit</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot" title="View documentation for matplotlib.pyplot.subplot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplot</span></a><spanclass="p">(</span><spanclass="mi">224</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot" title="View documentation for matplotlib.pyplot.plot"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">plot</span></a><spanclass="p">(</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">x</span></a><spanclass="p">,</span><ahref="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><spanclass="n">y</span></a><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.yscale.html#matplotlib.pyplot.yscale" title="View documentation for matplotlib.pyplot.yscale"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">yscale</span></a><spanclass="p">(</span><spanclass="s1">'logit'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.title.html#matplotlib.pyplot.title" title="View documentation for matplotlib.pyplot.title"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">title</span></a><spanclass="p">(</span><spanclass="s1">'logit'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.grid.html#matplotlib.pyplot.grid" title="View documentation for matplotlib.pyplot.grid"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">grid</span></a><spanclass="p">(</span><spanclass="kc">True</span><spanclass="p">)</span>
<spanclass="c1"># Format the minor tick labels of the y-axis into empty strings with</span>
<spanclass="c1"># `NullFormatter`, to avoid cumbering the axis with too many labels.</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.gca.html#matplotlib.pyplot.gca" title="View documentation for matplotlib.pyplot.gca"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">gca</span></a><spanclass="p">()</span><spanclass="o">.</span><spanclass="n">yaxis</span><spanclass="o">.</span><spanclass="n">set_minor_formatter</span><spanclass="p">(</span><ahref="../../api/ticker_api.html#matplotlib.ticker.NullFormatter" title="View documentation for matplotlib.ticker.NullFormatter"><spanclass="n">NullFormatter</span></a><spanclass="p">())</span>
<spanclass="c1"># Adjust the subplot layout, because the logit one may take more space</span>
<spanclass="c1"># than usual, due to y-tick labels like "1 - 10^{-3}"</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.subplots_adjust.html#matplotlib.pyplot.subplots_adjust" title="View documentation for matplotlib.pyplot.subplots_adjust"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplots_adjust</span></a><spanclass="p">(</span><spanclass="n">top</span><spanclass="o">=</span><spanclass="mf">0.92</span><spanclass="p">,</span><spanclass="n">bottom</span><spanclass="o">=</span><spanclass="mf">0.08</span><spanclass="p">,</span><spanclass="n">left</span><spanclass="o">=</span><spanclass="mf">0.10</span><spanclass="p">,</span><spanclass="n">right</span><spanclass="o">=</span><spanclass="mf">0.95</span><spanclass="p">,</span><spanclass="n">hspace</span><spanclass="o">=</span><spanclass="mf">0.25</span><spanclass="p">,</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="View documentation for matplotlib.pyplot.show"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">show</span></a><spanclass="p">()</span>
<p>It is also possible to add your own scale, see <aclass="reference internal" href="../../devel/add_new_projection.html#adding-new-scales"><spanclass="std std-ref">Developer's guide for creating scales and transformations</span></a> for
details.</p>
<divclass="sphx-glr-footer class sphx-glr-footer-example docutils container" id="sphx-glr-download-tutorials-introductory-pyplot-py">