@@ -11,17 +11,17 @@ Backends
1111What 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
2626To support all of these use cases, Matplotlib can target different
2727outputs, 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
250250Information 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 `).
0 commit comments