10000 Improve backends documentation · matplotlib/matplotlib@23f61e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 23f61e8

Browse files
committed
Improve backends documentation
1 parent 64ba969 commit 23f61e8

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
@@ -426,6 +442,10 @@ def my_plotter(ax, data1, data2, param_dict):
426442
# This backend can be activated in IPython with ``%matplotlib wx``.
427443
# ========= ================================================================
428444
#
445+
# .. note::
446+
# The names of builtin backends case-insensitive; e.g., 'Qt5Agg' and
447+
# 'qt5agg' are equivalent.
448+
#
429449
# .. _`Anti-Grain Geometry`: http://antigrain.com/
430450
# .. _Postscript: https://en.wikipedia.org/wiki/PostScript
431451
# .. _`Portable Document Format`: https://en.wikipedia.org/wiki/Portable_Document_Format
@@ -440,7 +460,7 @@ def my_plotter(ax, data1, data2, param_dict):
440460
# .. _PyQt5: https://riverbankcomputing.com/software/pyqt/intro
441461
#
442462
# ipympl
443-
# ------
463+
# ^^^^^^
444464
#
445465
# The Jupyter widget ecosystem is moving too fast to support directly in
446466
# Matplotlib. To install ipympl
@@ -460,13 +480,13 @@ def my_plotter(ax, data1, data2, param_dict):
460480
# for more details.
461481
#
462482
# GTK and Cairo
463-
# -------------
483+
# ^^^^^^^^^^^^^
464484
#
465485
# `GTK3` backends (*both* `GTK3Agg` and `GTK3Cairo`) depend on Cairo
466486
# (pycairo>=1.11.0 or cairocffi).
467487
#
468488
# How do I select PyQt4 or PySide?
469-
# --------------------------------
489+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
470490
#
471491
# The `QT_API` environment variable can be set to either `pyqt` or `pyside`
472492
# to use `PyQt4` or `PySide`, respectively.
@@ -475,10 +495,18 @@ def my_plotter(ax, data1, data2, param_dict):
475495
# :mod:`matplotlib` first tries to import it, if the import fails, it tries to
476496
# import `PySide`.
477497
#
498+
# Using non-builtin backends
499+
# --------------------------
500+
# More generally, any importable backend can be selected by using any of the
501+
# methods above. If `name.of.the.backend` is the module containing the backend,
502+
# use `module://name.of.the.backend` as the backend name, e.g.
503+
# `matplotlib.use('module://name.of.the.backend')`.
504+
#
505+
#
478506
# .. _interactive-mode:
479507
#
480508
# What is interactive mode?
481-
# ===================================
509+
# =========================
482510
#
483511
# Use of an interactive backend (see :ref:`what-is-a-backend`)
484512
# permits--but does not by itself require or ensure--plotting
@@ -511,7 +539,8 @@ def my_plotter(ax, data1, data2, param_dict):
511539
# Interactive mode works with suitable backends in ipython and in
512540
# the ordinary python shell, but it does *not* work in the IDLE IDE.
513541
# If the default backend does not support interactivity, an interactive
514-
# backend can be explicitly activated using any of the methods discussed in `What is a backend?`_.
542+
# backend can be explicitly activated using any of the methods discussed
543+
# in `What is a backend?`_.
515544
#
516545
#
517546
# Interactive example
@@ -524,18 +553,15 @@ def my_plotter(ax, data1, data2, param_dict):
524553
# plt.ion()
525554
# plt.plot([1.6, 2.7])
526555
#
527-
# Assuming you are running version 1.0.1 or higher, and you have
528-
# an interactive backend installed and selected by default, you should
529-
# see a plot, and your terminal prompt should also be active; you
530-
# can type additional commands such as::
556+
# This will pop up a plot window. Your terminal prompt will remain active, so
557+
# that you can type additional commands such as::
531558
#
532559
# plt.title("interactive test")
533560
# plt.xlabel("index")
534561
#
535-
# and you will see the plot being updated after each line. Since version 1.5,
536-
# modifying the plot by other means *should* also automatically
537-
# update the display on most backends. Get a reference to the :class:`~matplotlib.axes.Axes` instance,
538-
# and call a method of that instance::
562+
# On most interactive backends, the figure window will also be updated if you
563+
# change it via the object-oriented interface. E.g. get a reference to the
564+
# `~matplotlib.axes.Axes` instance, and call a method of that instance::
539565
#
540566
# ax = plt.gca()
541567
# ax.plot([3.1, 2.2])

0 commit comments

Comments
 (0)
0