<li><p><aclass="reference internal" href="#check-whether-a-figure-is-empty" id="id2">Check whether a figure is empty</a></p></li>
<li><p><aclass="reference internal" href="#find-all-objects-in-a-figure-of-a-certain-type" id="id3">Find all objects in a figure of a certain type</a></p></li>
<li><p><aclass="reference internal" href="#prevent-ticklabels-from-having-an-offset" id="id4">Prevent ticklabels from having an offset</a></p></li>
<li><p><aclass="reference internal" href="#generate-images-without-having-a-window-appear" id="id12">Generate images without having a window appear</a></p></li>
<li><p><aclass="reference internal" href="#work-with-threads" id="id13">Work with threads</a></p></li>
</ul>
</li>
</ul>
</div>
<sectionid="check-whether-a-figure-is-empty">
<spanid="howto-figure-empty"></span><h2>Check whether a figure is empty<aclass="headerlink" href="#check-whether-a-figure-is-empty" title="Permalink to this headline">¶</a></h2>
<p>Empty can actually mean different things. Does the figure contain any artists?
Does a figure with an empty <aclass="reference internal" href="../../api/axes_api.html#matplotlib.axes.Axes" title="matplotlib.axes.Axes"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Axes</span></code></a> still count as empty? Is the figure
empty if it was rendered pure white (there may be artists present, but they
could be outside the drawing area or transparent)?</p>
<p>For the purpose here, we define empty as: "The figure does not contain any
artists except it's background patch." The exception for the background is
necessary, because by default every figure contains a <aclass="reference internal" href="../../api/_as_gen/matplotlib.patches.Rectangle.html#matplotlib.patches.Rectangle" title="matplotlib.patches.Rectangle"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Rectangle</span></code></a> as it's
background patch. This definition could be checked via:</p>
<spanid="howto-findobj"></span><h2>Find all objects in a figure of a certain type<aclass="headerlink" href="#find-all-objects-in-a-figure-of-a-certain-type" title="Permalink to this headline">¶</a></h2>
<p>Every Matplotlib artist (see <aclass="reference internal" href="../../tutorials/intermediate/artists.html"><spanclass="doc">Artist tutorial</span></a>) has a method
called <aclass="reference internal" href="../../api/_as_gen/matplotlib.artist.Artist.findobj.html#matplotlib.artist.Artist.findobj" title="matplotlib.artist.Artist.findobj"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">findobj()</span></code></a> that can be used to
recursively search the artist for any artists it may contain that meet
some criteria (e.g., match all <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>
instances or match some arbitrary filter function). For example, the
following snippet finds every object in the figure which has a
<codeclass="docutils literal notranslate"><spanclass="pre">set_color</span></code> property and makes the object blue:</p>
<spanid="howto-supress-offset"></span><h2>Prevent ticklabels from having an offset<aclass="headerlink" href="#prevent-ticklabels-from-having-an-offset" title="Permalink to this headline">¶</a></h2>
<p>The default formatter will use an offset to reduce
the length of the ticklabels. To turn this feature
<p>set <codeclass="docutils literal notranslate"><aclass="reference external" href="../../tutorials/introductory/customizing.html?highlight=axes.formatter.useoffset#a-sample-matplotlibrc-file"><spanclass="pre">rcParams["axes.formatter.useoffset"]</span></a></code> (default: <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code>), or use a different
formatter. See <aclass="reference internal" href="../../api/ticker_api.html#module-matplotlib.ticker" title="matplotlib.ticker"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">ticker</span></code></a> for details.</p>
</section>
<sectionid="save-transparent-figures">
<spanid="howto-transparent"></span><h2>Save transparent figures<aclass="headerlink" href="#save-transparent-figures" title="Permalink to this headline">¶</a></h2>
<p>The <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.savefig.html#matplotlib.pyplot.savefig" title="matplotlib.pyplot.savefig"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">savefig()</span></code></a> command has a keyword argument
<em>transparent</em> which, if 'True', will make the figure and axes
backgrounds transparent when saving, but will not affect the displayed
image on the screen.</p>
<p>If you need finer grained control, e.g., you do not want full transparency
or you want to affect the screen displayed version as well, you can set
<spanid="howto-multipage"></span><h2>Save multiple plots to one pdf file<aclass="headerlink" href="#save-multiple-plots-to-one-pdf-file" title="Permalink to this headline">¶</a></h2>
<p>Many image file formats can only have one image per file, but some formats
support multi-page files. Currently, Matplotlib only provides multi-page
output to pdf files, using either the pdf or pgf backends, via the
<spanid="howto-auto-adjust"></span><h2>Make room for tick labels<aclass="headerlink" href="#make-room-for-tick-labels" title="Permalink to this headline">¶</a></h2>
<p>By default, Matplotlib uses fixed percentage margins around subplots. This can
lead to labels overlapping or being cut off at the figure boundary. There are
multiple ways to fix this:</p>
<ulclass="simple">
<li><p>Manually adapt the subplot parameters using <aclass="reference internal" href="../../api/figure_api.html#matplotlib.figure.Figure.subplots_adjust" title="matplotlib.figure.Figure.subplots_adjust"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Figure.subplots_adjust</span></code></a> /
<spanid="howto-align-label"></span><h2>Align my ylabels across multiple subplots<aclass="headerlink" href="#align-my-ylabels-across-multiple-subplots" title="Permalink to this headline">¶</a></h2>
<p>If you have multiple subplots over one another, and the y data have
different scales, you can often get ylabels that do not align
vertically across the multiple subplots, which can be unattractive.
By default, Matplotlib positions the x location of the ylabel so that
it does not overlap any of the y ticks. You can override this default
behavior by specifying the coordinates of the label. The example
below shows the default behavior in the left subplots, and the manual
<spanid="howto-set-zorder"></span><h2>Control the draw order of plot elements<aclass="headerlink" href="#control-the-draw-order-of-plot-elements" title="Permalink to this headline">¶</a></h2>
<p>The draw order of plot elements, and thus which elements will be on top, is
determined by the <aclass="reference internal" href="../../api/_as_gen/matplotlib.artist.Artist.set_zorder.html#matplotlib.artist.Artist.set_zorder" title="matplotlib.artist.Artist.set_zorder"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">set_zorder</span></code></a> property.
See <aclass="reference internal" href="../../gallery/misc/zorder_demo.html"><spanclass="doc">Zorder Demo</span></a> for a detailed description.</p>
<spanid="howto-axis-equal"></span><h2>Make the aspect ratio for plots equal<aclass="headerlink" href="#make-the-aspect-ratio-for-plots-equal" title="Permalink to this headline">¶</a></h2>
<p>See <aclass="reference internal" href="../../gallery/subplots_axes_and_figures/axis_equal_demo.html"><spanclass="doc">Equal axis aspect ratio</span></a> for a
complete example.</p>
</section>
<sectionid="draw-multiple-y-axis-scales">
<spanid="howto-twoscale"></span><h2>Draw multiple y-axis scales<aclass="headerlink" href="#draw-multiple-y-axis-scales" title="Permalink to this headline">¶</a></h2>
<p>A frequent request is to have two scales for the left and right
y-axis, which is possible using <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.twinx.html#matplotlib.pyplot.twinx" title="matplotlib.pyplot.twinx"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">twinx()</span></code></a> (more
than two scales are not currently supported, though it is on the wish
list). This works pretty well, though there are some quirks when you
are trying to interactively pan and zoom, because both scales do not get
<aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.twiny.html#matplotlib.pyplot.twiny" title="matplotlib.pyplot.twiny"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">twiny()</span></code></a>) to use <em>2 different axes</em>,
turning the axes rectangular frame off on the 2nd axes to keep it from
obscuring the first, and manually setting the tick locs and labels as
desired. You can use separate <codeclass="docutils literal notranslate"><spanclass="pre">matplotlib.ticker</span></code> formatters and
locators as desired because the two axes are independent.</p>
<p>See <aclass="reference internal" href="../../gallery/subplots_axes_and_figures/two_scales.html"><spanclass="doc">Plots with different scales</span></a> for a
<spanid="howto-batch"></span><h2>Generate images without having a window appear<aclass="headerlink" href="#generate-images-without-having-a-window-appear" title="Permalink to this headline">¶</a></h2>
<p>Simply do not call <aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="matplotlib.pyplot.show"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">show</span></code></a>, and directly save the figure to
<p><aclass="reference internal" href="../../gallery/user_interfaces/web_application_server_sgskip.html"><spanclass="doc">Embedding in a web application server (Flask)</span></a> for
information about running matplotlib inside of a web application.</p>
</div>
</section>
<sectionid="work-with-threads">
<spanid="how-to-threads"></span><h2>Work with threads<aclass="headerlink" href="#work-with-threads" title="Permalink to this headline">¶</a></h2>
<p>Matplotlib is not thread-safe: in fact, there are known race conditions
that affect certain artists. Hence, if you work with threads, it is your
responsibility to set up the proper locks to serialize access to Matplotlib
artists.</p>
<p>You may be able to work on separate figures from separate threads. However,
you must in that case use a <em>non-interactive backend</em> (typically Agg), because
most GUI backends <em>require</em> being run from the main thread as well.</p>