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
<liclass="toctree-l2"><aclass="reference internal" href="explain/figure/writing_a_backend_pyplot_interface.html">Writing a backend -- the pyplot interface</a></li>
</ul>
</details></li>
</ul>
<ulclass="nav bd-sidenav">
<liclass="toctree-l1 has-children"><aclass="reference internal" href="explain/axes/index.html">Axes and subplots</a><details><summary><spanclass="toctree-toggle" role="presentation"><iclass="fa-solid fa-chevron-down"></i></span></summary><ul>
<liclass="toctree-l2"><aclass="reference internal" href="explain/axes/axes_intro.html">Introduction to Axes (or Subplots)</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="explain/axes/arranging_axes.html">Arranging multiple Axes in a Figure</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="explain/artists/imshow_extent.html">Understanding the extent keyword argument of imshow</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="explain/text/pgf.html">Text rendering with XeLaTeX/LuaLaTeX via the <codeclass="docutils literal notranslate"><spanclass="pre">pgf</span></code> backend</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="explain/text/usetex.html">Text rendering with LaTeX</a></li>
</ul>
</details></li>
</ul>
<ulclass="nav bd-sidenav">
<liclass="toctree-l1 has-children"><aclass="reference internal" href="explain/animations/index.html">Animations using Matplotlib</a><details><summary><spanclass="toctree-toggle" role="presentation"><iclass="fa-solid fa-chevron-down"></i></span></summary><ul>
<liclass="toctree-l2"><aclass="reference internal" href="explain/animations/animations.html">Animations using Matplotlib</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="explain/animations/blitting.html">Faster rendering by using blitting</a></li>
<spanid="howto-faq"></span><h1>Frequently Asked Questions<aclass="headerlink" href="#frequently-asked-questions" title="Link to this heading">#</a></h1>
<sectionid="i-don-t-see-a-figure-window">
<spanid="how-do-no-figure"></span><h2>I don't see a figure window<aclass="headerlink" href="#i-don-t-see-a-figure-window" title="Link to this heading">#</a></h2>
<p>Please see <aclass="reference internal" href="explain/figure/backends.html#figures-not-showing"><spanclass="std std-ref">Debugging the figure windows not showing</span></a>.</p>
<spanid="how-to-too-many-ticks"></span><h2>Why do I have so many ticks, and/or why are they out of order?<aclass="headerlink" href="#why-do-i-have-so-many-ticks-and-or-why-are-they-out-of-order" title="Link to this heading">#</a></h2>
<p>One common cause for unexpected tick behavior is passing a <em>list of strings
instead of numbers or datetime objects</em>. This can easily happen without notice
when reading in a comma-delimited text file. Matplotlib treats lists of strings
as <em>categorical</em> variables
(<aclass="reference internal" href="../gallery/lines_bars_and_markers/categorical_variables.html"><spanclass="doc">Plotting categorical variables</span></a>), and by default
puts one tick per category, and plots them in the order in which they are
<spanclass="n">ax</span><spanclass="p">[</span><spanclass="mi">0</span><spanclass="p">]</span><spanclass="o">.</span><spanclass="n">set_title</span><spanclass="p">(</span><spanclass="s1">'Ticks seem out of order / misplaced'</span><spanclass="p">)</span>
<p>For more information see <aclass="reference internal" href="../gallery/ticks/ticks_too_many.html"><spanclass="doc">Fixing too many ticks</span></a>.</p>
<spanid="howto-determine-artist-extent"></span><h2>Determine the extent of Artists in the Figure<aclass="headerlink" href="#determine-the-extent-of-artists-in-the-figure" title="Link to this heading">#</a></h2>
<p>Sometimes we want to know the extent of an Artist. Matplotlib <aclass="reference internal" href="../api/artist_api.html#matplotlib.artist.Artist" title="matplotlib.artist.Artist"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Artist</span></code></a> objects
have a method <aclass="reference internal" href="../api/_as_gen/matplotlib.artist.Artist.get_window_extent.html#matplotlib.artist.Artist.get_window_extent" title="matplotlib.artist.Artist.get_window_extent"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Artist.get_window_extent</span></code></a> that will usually return the extent of
the artist in pixels. However, some artists, in particular text, must be
rendered at least once before their extent is known. Matplotlib supplies
<aclass="reference internal" href="../api/_as_gen/matplotlib.figure.Figure.draw_without_rendering.html#matplotlib.figure.Figure.draw_without_rendering" title="matplotlib.figure.Figure.draw_without_rendering"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Figure.draw_without_rendering</span></code></a>, which should be called before calling
<spanid="howto-figure-empty"></span><h2>Check whether a figure is empty<aclass="headerlink" href="#check-whether-a-figure-is-empty" title="Link to this heading">#</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/_as_gen/matplotlib.axes.Axes.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="Link to this heading">#</a></h2>
<p>Every Matplotlib artist (see <aclass="reference internal" href="../tutorials/artists.html#artists-tutorial"><spanclass="std std-ref">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-suppress-offset"></span><h2>Prevent ticklabels from having an offset<aclass="headerlink" href="#prevent-ticklabels-from-having-an-offset" title="Link to this heading">#</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 internal" href="explain/customizing.html?highlight=axes.formatter.useoffset#matplotlibrc-sample"><spanclass="std std-ref"><spanclass="pre">rcParams["axes.formatter.useoffset"]</span></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="Link to this heading">#</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="Link to this heading">#</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="Link to this heading">#</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/_as_gen/matplotlib.figure.Figure.subplots_adjust.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="Link to this heading">#</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. To learn how, see
<spanid="howto-set-zorder"></span><h2>Control the draw order of plot elements<aclass="headerlink" href="#control-the-draw-order-of-plot-elements" title="Link to this heading">#</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="Link to this heading">#</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="Link to this heading">#</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="Link to this heading">#</a></h2>
<p>The recommended approach since matplotlib 3.1 is to explicitly create a Figure
<p><aclass="reference internal" href="../gallery/user_interfaces/web_application_server_sgskip.html"><spanclass="doc">Embed 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="Link to this heading">#</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>
</section>
<sectionid="get-help">
<spanid="reporting-problems"></span><spanid="id1"></span><h2>Get help<aclass="headerlink" href="#get-help" title="Link to this heading">#</a></h2>
<p>There are a number of good resources for getting help with Matplotlib.
There is a good chance your question has already been asked:</p>
<ulclass="simple">
<li><p>The <aclass="reference external" href="https://discourse.matplotlib.org/c/community/matplotlib-users/6">mailing list archive</a>.</p></li>
<p>If you are unable to find an answer to your question through search, please
provide the following information in your e-mail to the <aclass="reference external" href="https://mail.python.org/mailman/listinfo/matplotlib-users">mailing list</a>:</p>
<ul>
<li><p>Your operating system (Linux/Unix users: post the output of <codeclass="docutils literal notranslate"><spanclass="pre">uname</span><spanclass="pre">-a</span></code>).</p></li>
<li><p>Where you obtained Matplotlib (e.g., your Linux distribution's packages,
GitHub, PyPI, or <aclass="reference external" href="https://www.anaconda.com/">Anaconda</a>).</p></li>
<li><p>Any customizations to your <codeclass="docutils literal notranslate"><spanclass="pre">matplotlibrc</span></code> file (see
<aclass="reference internal" href="explain/customizing.html#customizing"><spanclass="std std-ref">Customizing Matplotlib with style sheets and rcParams</span></a>).</p></li>
<li><p>If the problem is reproducible, please try to provide a <em>minimal</em>, standalone
Python script that demonstrates the problem. This is <em>the</em> critical step.
If you can't post a piece of code that we can run and reproduce your error,
the chances of getting help are significantly diminished. Very often, the
mere act of trying to minimize your code to the smallest bit that produces
the error will help you find a bug in <em>your</em> code that is causing the
problem.</p></li>
<li><p>Matplotlib provides debugging information through the <aclass="reference external" href="https://docs.python.org/3/library/logging.html#module-logging" title="(in Python v3.14)"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">logging</span></code></a> library, and
a helper function to set the logging level: one can call</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">set_loglevel</span><spanclass="p">(</span><spanclass="s2">"info"</span><spanclass="p">)</span><spanclass="c1"># or "debug" for more info</span>
</pre></div>
</div>
<p>to obtain this debugging information.</p>
<p>Standard functions from the <aclass="reference external" href="https://docs.python.org/3/library/logging.html#module-logging" title="(in Python v3.14)"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">logging</span></code></a> module are also applicable; e.g. one
could call <codeclass="docutils literal notranslate"><spanclass="pre">logging.basicConfig(level="DEBUG")</span></code> even before importing
Matplotlib (this is in particular necessary to get the logging info emitted
during Matplotlib's import), or attach a custom handler to the "matplotlib"
logger. This may be useful if you use a custom logging configuration.</p>
</li>
</ul>
<p>If you compiled Matplotlib yourself, please also provide:</p>
<ul>
<li><p>your compiler version -- e.g., <codeclass="docutils literal notranslate"><spanclass="pre">gcc</span><spanclass="pre">--version</span></code>.</p></li>
<p>The beginning of the build output contains lots of details about your
platform that are useful for the Matplotlib developers to diagnose your
problem.</p>
</li>
</ul>
<p>If you compiled an older version of Matplotlib using the pre-Meson build system, instead
provide:</p>
<ul>
<li><p>any changes you have made to <codeclass="docutils literal notranslate"><spanclass="pre">setup.py</span></code>/<codeclass="docutils literal notranslate"><spanclass="pre">setupext.py</span></code>,</p></li>
<liclass="toc-h2 nav-item toc-entry"><aclass="reference internal nav-link" href="#i-don-t-see-a-figure-window">I don't see a figure window</a></li>
<liclass="toc-h2 nav-item toc-entry"><aclass="reference internal nav-link" href="#why-do-i-have-so-many-ticks-and-or-why-are-they-out-of-order">Why do I have so many ticks, and/or why are they out of order?</a></li>
<liclass="toc-h2 nav-item toc-entry"><aclass="reference internal nav-link" href="#determine-the-extent-of-artists-in-the-figure">Determine the extent of Artists in the Figure</a></li>
<liclass="toc-h2 nav-item toc-entry"><aclass="reference internal nav-link" href="#check-whether-a-figure-is-empty">Check whether a figure is empty</a></li>
<liclass="toc-h2 nav-item toc-entry"><aclass="reference internal nav-link" href="#find-all-objects-in-a-figure-of-a-certain-type">Find all objects in a figure of a certain type</a></li>
<liclass="toc-h2 nav-item toc-entry"><aclass="reference internal nav-link" href="#prevent-ticklabels-from-having-an-offset">Prevent ticklabels from having an offset</a></li>
<liclass="toc-h2 nav-item toc-entry"><aclass="reference internal nav-link" href="#save-multiple-plots-to-one-pdf-file">Save multiple plots to one pdf file</a></li>
<liclass="toc-h2 nav-item toc-entry"><aclass="reference internal nav-link" href="#make-room-for-tick-labels">Make room for tick labels</a></li>
<liclass="toc-h2 nav-item toc-entry"><aclass="reference internal nav-link" href="#align-my-ylabels-across-multiple-subplots">Align my ylabels across multiple subplots</a></li>
<liclass="toc-h2 nav-item toc-entry"><aclass="reference internal nav-link" href="#control-the-draw-order-of-plot-elements">Control the draw order of plot elements</a></li>
<liclass="toc-h2 nav-item toc-entry"><aclass="reference internal nav-link" href="#make-the-aspect-ratio-for-plots-equal">Make the aspect ratio for plots equal</a></li>
<liclass="toc-h2 nav-item toc-entry"><aclass="reference internal nav-link" href="#generate-images-without-having-a-window-appear">Generate images without having a window appear</a></li>
<liclass="toc-h2 nav-item toc-entry"><aclass="reference internal nav-link" href="#work-with-threads">Work with threads</a></li>