Skip to content

Commit 823d60d

Browse files
committed
DOC: some debug steps for backend issues [ci doc]
1 parent f05167c commit 823d60d

File tree

6 files changed

+112
-16
lines changed

6 files changed

+112
-16
lines changed

doc/users/faq.rst

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
Frequently Asked Questions
99
==========================
1010

11+
.. _how-do-no-figure:
12+
13+
I don't see a figure window
14+
---------------------------
15+
16+
Please see :ref:`figures-not-showing`.
17+
1118
.. _how-to-too-many-ticks:
1219

1320
Why do I have so many ticks, and/or why are they out of order?
@@ -301,6 +308,7 @@ you must in that case use a *non-interactive backend* (typically Agg), because
301308
most GUI backends *require* being run from the main thread as well.
302309

303310
.. _reporting-problems:
311+
.. _get-help:
304312

305313
Get help
306314
--------

galleries/users_explain/figure/backends.rst

+95-11
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ Backends
1111
What is a backend?
1212
------------------
1313

14-
A lot of documentation on the website and in the mailing lists refers
15-
to the "backend" and many new users are confused by this term.
16-
Matplotlib targets many different use cases and output formats. Some
17-
people use Matplotlib interactively from the Python shell and have
18-
plotting windows pop up when they type commands. Some people run
19-
`Jupyter <https://jupyter.org>`_ notebooks and draw inline plots for
20-
quick data analysis. Others embed Matplotlib into graphical user
21-
interfaces like PyQt or PyGObject to build rich applications. Some
22-
people use Matplotlib in batch scripts to generate postscript images
23-
from numerical simulations, and still others run web application
24-
servers to dynamically serve up graphs.
14+
Backends are used for displaying Matplotlib figures (see :ref:`figure-intro`),
15+
on the screen, or for writing to files. A lot of documentation on the website
16+
and in the mailing lists refers to the "backend" and many new users are
17+
confused by this term. Matplotlib targets many different use cases and output
18+
formats. Some people use Matplotlib interactively from the Python shell and
19+
have plotting windows pop up when they type commands. Some people run `Jupyter
20+
<https://jupyter.org>`_ notebooks and draw inline plots for quick data
21+
analysis. Others embed Matplotlib into graphical user interfaces like PyQt or
22+
PyGObject to build rich applications. Some people use Matplotlib in batch
23+
scripts to generate postscript images from numerical simulations, and still
24+
others run web application servers to dynamically serve up graphs.
2525

2626
To support all of these use cases, Matplotlib can target different
2727
outputs, and each of these capabilities is called a backend; the
@@ -248,3 +248,87 @@ backend, use ``module://name.of.the.backend`` as the backend name, e.g.
248248
``matplotlib.use('module://name.of.the.backend')``.
249249

250250
Information for backend implementers is available at :ref:`writing_backend_interface`.
251+
252+
.. _figures-not-showing:
253+
254+
Debugging the figure windows not showing
255+
----------------------------------------
256+
257+
Sometimes things do not work as expected, usually during an install.
258+
259+
If you are using a Notebook or integrated development environment (see :ref:`notebooks-and-ides`),
260+
please consult their documentation for debugging figures not working in their
261+
environments.
262+
263+
If you are using one of Matplotlib's graphics backends (see :ref:`standalone-scripts-and-interactive-use`), make sure you know which
264+
one is being used:
265+
266+
.. code-block:: python3
267+
268+
import matplotlib
269+
270+
print(matplotlib.get_backend())
271+
272+
Try a simple plot to see if the GUI opens:
273+
274+
.. code-block:: python3
275+
276+
import matplotlib
277+
import matplotlib.pyplot as plt
278+
279+
print(matplotlib.get_backend())
280+
plt.plot((1, 4, 6))
281+
plt.show()
282+
283+
If it does not, you perhaps have an installation problem. A good step at this
284+
point is to ensure that your GUI toolkit is installed properly, taking
285+
Matplotlib out of the testing. Almost all GUI toolkits have a small test
286+
program that can be run to test basic functionality. If this test fails, try re-installing.
287+
288+
QtAgg, QtCairo, Qt5Agg, and Qt5Cairo
289+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
290+
291+
Test ``PyQt5``.
292+
293+
If you have ``PySide`` or ``PyQt6`` installed rather than ``PyQt5``, just change the import
294+
accordingly:
295+
296+
.. code-block:: bash
297+
298+
python -c "from PyQt5.QtWidgets import *; app = QApplication([]); win = QMainWindow(); win.show(); app.exec()"
299+
300+
301+
TkAgg and TkCairo
302+
^^^^^^^^^^^^^^^^^
303+
304+
Test ``tkinter``:
305+
306+
.. code-block:: bash
307+
308+
python3 -c "from tkinter import Tk; Tk().mainloop()"
309+
310+
GTK3Agg, GTK4Agg, GTK3Cairo, GTK4Cairo
311+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
312+
313+
Test ``Gtk``:
314+
315+
.. code-block:: bash
316+
317+
python3 -c "from gi.repository import Gtk; win = Gtk.Window(); win.connect('destroy', Gtk.main_quit); win.show(); Gtk.main()"
318+
319+
wxAgg and wxCairo
320+
^^^^^^^^^^^^^^^^^
321+
322+
Test ``wx``:
323+
324+
.. code-block:: python3
325+
326+
import wx
327+
328+
app = wx.App(False) # Create a new app, don't redirect stdout/stderr to a window.
329+
frame = wx.Frame(None, wx.ID_ANY, "Hello World") # A Frame is a top-level window.
330+
frame.Show(True) # Show the frame.
331+
app.MainLoop()
332+
333+
If the test works for your desired backend but you still cannot get Matplotlib to display a figure, then contact us (see
334+
:ref:`get-help`).

galleries/users_explain/figure/figure_intro.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
.. redirect-from:: /users/explain/figure
33

4-
.. _figure_explanation:
4+
.. _figure-intro:
55

66
+++++++++++++++++++++++
77
Introduction to Figures
@@ -36,6 +36,8 @@ We will discuss how to create Figures in more detail below, but first it is
3636
helpful to understand how to view a Figure. This varies based on how you are
3737
using Matplotlib, and what :ref:`Backend <what-is-a-backend>` you are using.
3838

39+
.. _notebooks-and-ides:
40+
3941
Notebooks and IDEs
4042
------------------
4143

@@ -82,6 +84,8 @@ other than the default "inline" backend, you will likely need to use an ipython
8284

8385
%matplotlib notebook
8486

87+
.. _standalone-scripts-and-interactive-use:
88+
8589
Standalone scripts and interactive use
8690
--------------------------------------
8791

galleries/users_explain/figure/interactive.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mouse-location tools built into the Matplotlib GUI windows are often sufficient,
1515
you can also use the event system to build customized data exploration tools.
1616

1717
.. seealso::
18-
:ref:`figure_explanation`.
18+
:ref:`figure-intro`.
1919

2020

2121
Matplotlib ships with :ref:`backends <what-is-a-backend>` binding to

galleries/users_explain/quick_start.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#
3939
# Note that to get this Figure to display, you may have to call ``plt.show()``,
4040
# depending on your backend. For more details of Figures and backends, see
41-
# :ref:`figure_explanation`.
41+
# :ref:`figure-intro`.
4242
#
4343
# .. _figure_parts:
4444
#
@@ -71,7 +71,7 @@
7171
# :ref:`Matplotlib backends <backends>` support zooming and
7272
# panning on figure windows.
7373
#
74-
# For more on Figures, see :ref:`figure_explanation`.
74+
# For more on Figures, see :ref:`figure-intro`.
7575
#
7676
# :class:`~matplotlib.axes.Axes`
7777
# ------------------------------

lib/matplotlib/figure.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
Some situations call for directly instantiating a `~.figure.Figure` class,
2525
usually inside an application of some sort (see :ref:`user_interfaces` for a
2626
list of examples) . More information about Figures can be found at
27-
:ref:`figure_explanation`.
27+
:ref:`figure-intro`.
2828
"""
2929

3030
from contextlib import ExitStack

0 commit comments

Comments
 (0)