8000 Improve backends documentation · matplotlib/matplotlib@cebd72d · GitHub
[go: up one dir, main page]

Skip to content

Commit cebd72d

Browse files
committed
Improve backends documentation
1 parent e1f0101 commit cebd72d

File tree

1 file changed

+61
-26
lines changed

1 file changed

+61
-26
lines changed

tutorials/introductory/usage.py

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -290,44 +290,60 @@ def my_plotter(ax, data1, data2, param_dict):
290290
# "interactive backends") and hardcopy backends to make image files
291291
# (PNG, SVG, PDF, PS; also referred to as "non-interactive backends").
292292
#
293-
# There are three ways to configure your backend. If they conflict each other,
294-
# the method mentioned last in the following list will be used, e.g. calling
295-
# :func:`~matplotlib.use()` will override the setting in your ``matplotlibrc``.
293+
# Selecting a backend
294+
# -------------------
296295
#
297-
# #. The :rc:`backend` parameter in your ``matplotlibrc`` file (see
298-
# :doc:`/tutorials/introductory/customizing`)::
296+
# There are three ways to configure your backend:
297+
#
298+
# 1. The :rc:`backend` parameter in your ``matplotlibrc`` file
299+
# 2. The :envvar:`MPLBACKEND` environment variable
300+
# 3. The function :func:`matplotlib.use`
301+
#
302+
# A more detailed description is given below.
303+
#
304+
# If multiple of these are configurations are present, the last one from the
305+
# list takes precedence; e.g. calling :func:`matplotlib.use()` will override
306+
# the setting in your ``matplotlibrc``.
307+
#
308+
# If no backend is explicitly set, Matplotlib automatically detects a usable
309+
# backend based on what is available on your system and on whether a GUI event
310+
# loop is already running. On Linux, if the environment variable
311+
# :envvar:`DISPLAY` is unset, the "event loop" is identified as "headless",
312+
# which causes a fallback to a noninteractive backend (agg).
313+
#
314+
# Here is a detailed description of the configuration methods:
315+
#
316+
# #. Setting :rc:`backend` in your ``matplotlibrc`` file::
299317
#
300318
# backend : qt5agg # use pyqt5 with antigrain (agg) rendering
301319
#
302-
# If no backend is explicitly set in the ``matplotlibrc`` file, Matplotlib
303-
# automatically detects a usable backend based on what is available on your
304-
# system and on whether a GUI event loop is already running.
320+
# See also :doc:`/tutorials/introductory/customizing`.
305321
#
306-
# On Linux, if the environment variable :envvar:`DISPLAY` is unset, the
307-
# "event loop" is identified as "headless", which causes a fallback to a
308-
# noninteractive backend (agg).
322+
# #. Setting the :envvar:`MPLBACKEND` environment variable:
309323
#
310-
# #. Setting the :envvar:`MPLBACKEND` environment variable, either for your
311-
# current shell or for a single script. On Unix::
324+
# You can set the environment variable either for your current shell or for
325+
# a single script.
312326
#
313-
# > export MPLBACKEND=module://my_backend
327+
# On Unix::
328+
#
329+
# > export MPLBACKEND=qt5agg
314330
# > python simple_plot.py
315331
#
316-
# > MPLBACKEND="module://my_backend" python simple_plot.py
332+
# > MPLBACKEND="qt5agg" python simple_plot.py
317333
#
318334
# On Windows, only the former is possible::
319335
#
320-
# > set MPLBACKEND=module://my_backend
336+
# > set MPLBACKEND=qt5agg
321337
# > python simple_plot.py
322338
#
323339
# Setting this environment variable will override the ``backend`` parameter
324340
# in *any* ``matplotlibrc``, even if there is a ``matplotlibrc`` in your
325-
# current working directory. Therefore setting :envvar:`MPLBACKEND`
341+
# current working directory. Therefore, setting :envvar:`MPLBACKEND`
326342
# globally, e.g. in your ``.bashrc`` or ``.profile``, is discouraged as it
327343
# might lead to counter-intuitive behavior.
328344
#
329-
# #. If your script depends on a specific backend you can use the
330-
# :func:`~matplotlib.use` function::
345+
# #. If your script depends on a specific backend you can use the function
346+
# :func:`matplotlib.use`::
331347
#
332348
# import matplotlib
333349
# matplotlib.use('PS') # generate postscript output by default
@@ -340,9 +356,9 @@ def my_plotter(ax, data1, data2, param_dict):
340356
# use a different backend. Therefore, you should avoid explicitly calling
341357
# `~matplotlib.use` unless absolutely necessary.
342358
#
343-
# .. note::
344-
# Backend name specifications are not case-sensitive; e.g., 'GTK3Agg'
345-
# and 'gtk3agg' are equivalent.
359+
#
360+
# The builtlin backends
361+
# ---------------------
346362
#
347363
# With a typical installation of matplotlib, such as from a
348364
# binary installer or a linux distribution package, a good default
@@ -424,6 +440,10 @@ def my_plotter(ax, data1, data2, param_dict):
424440
# This backend can be activated in IPython with ``%matplotlib wx``.
425441
# ========= ================================================================
426442
#
443+
# .. note::
444+
# Backend name specifications are case-insensitive; e.g., 'Qt5Agg'
445+
# and 'qt5agg' are equivalent.
446+
#
427447
# .. _`Anti-Grain Geometry`: http://antigrain.com/
428448
# .. _Postscript: https://en.wikipedia.org/wiki/PostScript
429449
# .. _`Portable Document Format`: https://en.wikipedia.org/wiki/Portable_Document_Format
@@ -438,7 +458,7 @@ def my_plotter(ax, data1, data2, param_dict):
438458
# .. _PyQt5: https://riverbankcomputing.com/software/pyqt/intro
439459
#
440460
# ipympl
441-
# ------
461+
# ^^^^^^
442462
#
443463
# The Jupyter widget ecosystem is moving too fast to support directly in
444464
# Matplotlib. To install ipympl
@@ -458,13 +478,13 @@ def my_plotter(ax, data1, data2, param_dict):
458478
# for more details.
459479
#
460480
# GTK and Cairo
461-
# -------------
481+
# ^^^^^^^^^^^^^
462482
#
463483
# `GTK3` backends (*both* `GTK3Agg` and `GTK3Cairo`) depend on Cairo
464484
# (pycairo>=1.11.0 or cairocffi).
465485
#
466486
# How do I select PyQt4 or PySide?
467-
# --------------------------------
487+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
468488
#
469489
# The `QT_API` environment variable can be set to either `pyqt` or `pyside`
470490
# to use `PyQt4` or `PySide`, respectively.
@@ -473,10 +493,25 @@ def my_plotter(ax, data1, data2, param_dict):
473493
# :mod:`matplotlib` first tries to import it, if the import fails, it tries to
474494
# import `PySide`.
475495
#
496+
# Using non-builtin backends
497+
# --------------------------
498+
# 3rd parties can provide additional backends. Some of them (e.g. jupyter and
499+
# pycharm have their own way of activation). However, there is also a generic
500+
# way to activate non-builtin backends. If you have a module ``my_backend``
501+
# that implements a backend:
502+
#
503+
# a) Make sure, it can be imported (e.g. by regular installation or by putting
504+
# it on the PYTHONPATH).
505+
# b) Select the backend via one of the methods above by using
506+
# ``module://my_backend`` as the backend name, e.g. ::
507+
#
508+
# matplotlib.use('module://my_backend')
509+
#
510+
#
476511
# .. _interactive-mode:
477512
#
478513
# What is interactive mode?
479-
# ===================================
514+
# =========================
480515
#
481516
# Use of an interactive backend (see :ref:`what-is-a-backend`)
482517
# permits--but does not by itself require or ensure--plotting

0 commit comments

Comments
 (0)
0