8000 Improve backends documentation (#14549) · matplotlib/matplotlib@0f54425 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f54425

Browse files
authored
Improve backends documentation (#14549)
Improve backends documentation
2 parents dc1bf99 + 23f61e8 commit 0f54425

File tree

1 file changed

+62
-36
lines changed

1 file changed

+62
-36
lines changed

tutorials/introductory/usage.py

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
#
187187
# Matplotlib's documentation and examples use both the OO and the pyplot
188188
# approaches (which are equally powerful), and you should feel free to use
189-
# either (however, it is preferrable pick one of them and stick to it, instead
189+
# either (however, it is preferable pick one of them and stick to it, instead
190190
# of mixing them). In general, we suggest to restrict pyplot to interactive
191191
# plotting (e.g., in a Jupyter notebook), and to prefer the OO-style for
192192
# non-interactive plotting (in functions and scripts that are intended to be
@@ -289,44 +289,60 @@ def my_plotter(ax, data1, data2, param_dict):
289289
# "interactive backends") and hardcopy backends to make image files
290290
# (PNG, SVG, PDF, PS; also referred to as "non-interactive backends").
291291
#
292-
# There are three ways to configure your backend. If they conflict each other,
293-
# the method mentioned last in the following list will be used, e.g. calling
294-
# :func:`~matplotlib.use()` will override the setting in your ``matplotlibrc``.
292+
# Selecting a backend
293+
# -------------------
295294
#
296-
# #. The :rc:`backend` parameter in your ``matplotlibrc`` file (see
297-
# :doc:`/tutorials/introductory/customizing`)::
295+
# There are three ways to configure your backend:
296+
#
297+
# 1. The :rc:`backend` parameter in your ``matplotlibrc`` file
298+
# 2. The :envvar:`MPLBACKEND` environment variable
299+
# 3. The function :func:`matplotlib.use`
300+
#
301+
# A more detailed description is given below.
302+
#
303+
# If multiple of these are configurations are present, the last one from the
304+
# list takes precedence; e.g. calling :func:`matplotlib.use()` will override
305+
# the setting in your ``matplotlibrc``.
306+
#
307+
# If no backend is explicitly set, Matplotlib automatically detects a usable
308+
# backend based on what is available on your system and on whether a GUI event
309+
# loop is already running. On Linux, if the environment variable
310+
# :envvar:`DISPLAY` is unset, the "event loop" is identified as "headless",
311+
# which causes a fallback to a noninteractive backend (agg).
312+
#
313+
# Here is a detailed description of the configuration methods:
314+
#
315+
# #. Setting :rc:`backend` in your ``matplotlibrc`` file::
298316
#
299317
# backend : qt5agg # use pyqt5 with antigrain (agg) rendering
300318
#
301-
# If no backend is explicitly set in the ``matplotlibrc`` file, Matplotlib
302-
# automatically detects a usable backend based on what is available on your
303-
# system and on whether a GUI event loop is already running.
319+
# See also :doc:`/tutorials/introductory/customizing`.
320+
#
321+
# #. Setting the :envvar:`MPLBACKEND` environment variable:
304322
#
305-
# On Linux, if the environment variable :envvar:`DISPLAY` is unset, the
306-
# "event loop" is identified as "headless", which causes a fallback to a
307-
# noninteractive backend (agg).
323+
# You can set the environment variable either for your current shell or for
324+
# a single script.
308325
#
309-
# #. Setting the :envvar:`MPLBACKEND` environment variable, either for your
310-
# current shell or for a single script. On Unix::
326+
# On Unix::
311327
#
312-
# > export MPLBACKEND=module://my_backend
328+
# > export MPLBACKEND=qt5agg
313329
# > python simple_plot.py
314330
#
315-
# > MPLBACKEND="module://my_backend" python simple_plot.py
331+
# > MPLBACKEND=qt5agg python simple_plot.py
316332
#
317333
# On Windows, only the former is possible::
318334
#
319-
# > set MPLBACKEND=module://my_backend
335+
# > set MPLBACKEND=qt5agg
320336
# > python simple_plot.py
321337
#
322338
# Setting this environment variable will override the ``backend`` parameter
323339
# in *any* ``matplotlibrc``, even if there is a ``matplotlibrc`` in your
324-
# current working directory. Therefore setting :envvar:`MPLBACKEND`
340+
# current working directory. Therefore, setting :envvar:`MPLBACKEND`
325341
# globally, e.g. in your ``.bashrc`` or ``.profile``, is discouraged as it
326342
# might lead to counter-intuitive behavior.
327343
#
328-
# #. If your script depends on a specific backend you can use the
329-
# :func:`~matplotlib.use` function::
344+
# #. If your script depends on a specific backend you can use the function
345+
# :func:`matplotlib.use`::
330346
#
331347
# import matplotlib
332348
# matplotlib.use('PS') # generate postscript output by default
@@ -339,9 +355,9 @@ def my_plotter(ax, data1, data2, param_dict):
339355
# use a different backend. Therefore, you should avoid explicitly calling
340356
# `~matplotlib.use` unless absolutely necessary.
341357
#
342-
# .. note::
343-
# Backend name specifications are not case-sensitive; e.g., 'GTK3Agg'
344-
# and 'gtk3agg' are equivalent.
358+
#
359+
# The builtin backends
360+
# --------------------
345361
#
346362
# With a typical installation of matplotlib, such as from a
347363
# 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+
# The names of builtin backends case-insensitive; e.g., 'Qt5Agg' and
445+
# '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,18 @@ 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+
# More generally, any importable backend can be selected by using any of the
499+
# methods above. If `name.of.the.backend` is the module containing the backend,
500+
# use `module://name.of.the.backend` as the backend name, e.g.
501+
# `matplotlib.use('module://name.of.the.backend')`.
502+
#
503+
#
476504
# .. _interactive-mode:
477505
#
478506
# What is interactive mode?
479-
# ===================================
507+
# =========================
480508
#
481509
# Use of an interactive backend (see :ref:`what-is-a-backend`)
482510
# permits--but does not by itself require or ensure--plotting
@@ -509,7 +537,8 @@ def my_plotter(ax, data1, data2, param_dict):
509537
# Interactive mode works with suitable backends in ipython and in
510538
# the ordinary python shell, but it does *not* work in the IDLE IDE.
511539
# If the default backend does not support interactivity, an interactive
512-
# backend can be explicitly activated using any of the methods discussed in `What is a backend?`_.
540+
# backend can be explicitly activated using any of the methods discussed
541+
# in `What is a backend?`_.
513542
#
514543
#
515544
# Interactive example
@@ -522,18 +551,15 @@ def my_plotter(ax, data1, data2, param_dict):
522551
# plt.ion()
523552
# plt.plot([1.6, 2.7])
524553
#
525-
# Assuming you are running version 1.0.1 or higher, and you have
526-
# an interactive backend installed and selected by default, you should
527-
# see a plot, and your terminal prompt should also be active; you
528-
# can type additional commands such as::
554+
# This will pop up a plot window. Your terminal prompt will remain active, so
555+
# that you can type additional commands such as::
529556
#
530557
# plt.title("interactive test")
531558
# plt.xlabel("index")
532559
#
533-
# and you will see the plot being updated after each line. Since version 1.5,
534-
# modifying the plot by other means *should* also automatically
535-
# update the display on most backends. Get a reference to the :class:`~matplotlib.axes.Axes` instance,
536-
# and call a method of that instance::
560+
# On most interactive backends, the figure window will also be updated if you
561+
# change it via the object-oriented interface. E.g. get a reference to the
562+
# `~matplotlib.axes.Axes` instance, and call a method of that instance::
537563
#
538564
# ax = plt.gca()
539565
# ax.plot([3.1, 2.2])

0 commit comments

Comments
 (0)
0